2010-09-17 115 views
1

我想学习Vim编辑器,我试图编译一个C文件。我已经安装了MinGW和我添加gcc.exe到系统路径:在Windows XP中编译C

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Arquivos de programas\TortoiseSVN\bin;c:\Arquivos de programas\Microsoft SQL Server\100\Tools\Binn\;c:\Arquivos de programas\Microsoft SQL Server\100\DTS\Binn\;C:\MinGW\bin\ 

在Vim的,我所做的: :GCC code.c -o gcc.exe 一个cmd窗口下面的开text:

C:\WINDOWS\system32\cmd.exe /c gcc -Wall code.c -o code.exe 
gcc: code.c: No such file or directory 
gcc: no input files 
shell returned 1 
Hit any key to close this window... 

怎么了? 谢谢。

+2

您需要从'code.c'所在的目录执行命令。 – Oded 2010-09-17 13:50:11

+0

也许你试图编译被调用的UB的程序(或为什么这个标记为“c”?) – pmg 2010-09-17 13:51:00

+0

C:\ code.c - 如何更改目录然后在vim中运行它? – gazu 2010-09-17 13:52:50

回答

2

完全.vimrcthis question,你需要的路线是:

" Automatically cd into the directory that the file is in 
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ') 
+0

很酷。这真的很有用!谢谢!你能解释这条线吗? – gazu 2010-09-17 14:02:14

+0

其实......不:)我只是用它而已 - 但是':help'是你的朋友,'autocmd'命令在'40.3'中覆盖了。 – 2010-09-17 14:17:15

+0

好的,非常感谢。 – gazu 2010-09-17 14:44:59

0

有没有可能是你的文件实际上是一个名为“code.c.something”。 Windows喜欢在没有询问的情况下为文件添加额外的结尾。这可能不是解决方案,但需要注意。

+0

你从哪里得到Windows喜欢这样的想法? – ysap 2010-09-18 05:41:35

+0

Windows中的默认样式设置将隐藏文件扩展名,并在保存文件时自动添加文件扩展名。如果您允许隐藏所有文件扩展名,那么您不知道文件的名称。 – luther07 2010-09-27 14:04:55