[英]How do I compile C programs using Vim's 'make' command with Visual Studio's compiler on Windows 7?
I'm trying to set up Vim to user VS (express) C compiler cl.exe
. 我正在尝试将Vim设置为用户VS(快速)C编译器
cl.exe
。 Adding 添加
set makrprg='c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.exe'
(I've tried escaping with \\\\
, \\\\\\
, \\\\\\\\
just to be sure) to my _vimrc
file and invoking :make %
returns the following: (我已经尝试使用
\\\\
, \\\\\\
, \\\\\\\\
以确保转义到我的_vimrc
文件并调用:make %
返回以下内容:
:! myfile.c >C:\Users\gvkv\AppData\Local\Temp\VIe7BF5.tmp 2>&1
and the loads myfile.c
into VS's IDE! 并将
myfile.c
加载到VS的IDE中! Even if cl.exe
needs its environment: 即使
cl.exe
需要它的环境:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat
this is still strange and I have no idea how to proceed. 这仍然很奇怪,我不知道如何继续。
Judge Maygarden's solution is correct up to proper escaping and solved the Vim problem I had but there were a couple of other issues that I had to resolve to make things work. Maygarden法官的解决方案是正确的,可以解决我遇到的Vim问题,但还有一些其他问题需要我解决才能使事情发生。 In particular
尤其是
cl.exe
requires the correct environment as well as the correct path; cl.exe
需要正确的环境以及正确的路径; ie, adding C:\\my\\path\\to\\cl
isn't sufficient. 即,将
C:\\my\\path\\to\\cl
是不够的。 Otherwise you will get errors reporting on missing DLL
s. 否则,您将收到有关丢失
DLL
的错误报告。 The solution is to run vcvars32.bat
(or any other batch file which sets up a similar environment) and cl
as a single command. 解决方案是运行
vcvars32.bat
(或任何其他设置类似环境的批处理文件)和cl
作为单个命令。
cmd
requires any paths with spaces to be double quoted but you can't escape them with \\
because :! ...
cmd
要求任何带空格的路径都是双引号但你不能用\\
来转义它们因为:! ...
:! ...
treats \\
literally; :! ...
对待\\
字面; instead, you must double quote the double quote, ""...
. 相反,你必须双引双引号,
""...
So, for completeness I thought I'd post my actual solution. 所以,为了完整性,我想我会发布我的实际解决方案。 In Vim (or
_vimrc
): 在Vim(或
_vimrc
)中:
:set makeprg=\"\"Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\ 10.0\\VC\\bin\\vcvars32.bat\"\&\&cl\"
and then you can simply call 然后你可以简单地打电话
:make %
and you're done. 你完成了
This method is easily generalizable for any compiler. 对于任何编译器,此方法都很容易推广。 Also, as devemouse's answer suggests, creating a makefile for
nmake
is probably the best way to go about doing things for any non-trivially sized project (I wanted a Vim-only solution that suits my current work). 此外,正如devemouse的回答所暗示的那样,为
nmake
创建一个makefile可能是为任何非平凡大小的项目做事的最佳方式(我想要一个适合我当前工作的仅限Vim的解决方案)。
I created a makefile where I had such target: 我创建了一个makefile ,我有这样的目标:
VCPROJ = /path/to/MyProject.vcproj
all:
"c:\Program Files\Microsoft Visual Studio 9.0\VC\vcpackages\vcbuild.exe" /nocolor /r $(VCPROJ) Debug
.PHONY: all
I had make
in vim's path so did not have to modify makeprg
. 我只好
make
Vim的路径,并没有修改makeprg
。
This way VS compiled normally whole project and vim parsed the errors. 这种方式VS正常编译整个项目并且vim解析了错误。
I believe the problem with your makeprg statement is mostly due to the spaces in the path. 我相信你的makeprg语句的问题主要是由于路径中的空格。 Cmd.exe requires double quotes around the spaces.
Cmd.exe需要空格周围的双引号。 First, use escaped double quotes around the path (\\"). Next escape all back slashes (\\). Finally, escape all spaces (\\ ).
首先,在路径(\\“)周围使用转义双引号。接下来转义所有反斜杠(\\)。最后,转义所有空格(\\)。
set makrprg=\"c:\\Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\ 10.0\\VC\\bin\\cl.exe\"
Alternatively, you could setup your PATH appropriately and just set makeprg to cl.exe directly. 或者,您可以适当地设置PATH并直接将makeprg设置为cl.exe 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.