简体   繁体   中英

How do I compile and run a C++ program from Vim?

Whenever I use the :!make % command, vim returns "make is not recognized as an internal or external command, operable program, or batch file." I have tried set makrprg=\\"C:\\\\Program\\ Files\\ (x86)\\\\Microsoft\\ Visual\\ Studio\\ 14.0\\\\VC\\\\bin\\\\cl.exe\\" . However, the same message appears. I believe the error may be in the path I have set, or the format of my statement; however, I am not sure if there is any other underlying cause.

I would greatly appreciate any input. Thanks in advance!

FYI:

I use a Windows 8 computer, and the compiler I typically use is the Microsoft Visual Studio 14.0 compiler.

! is a VIM command that invokes the shell. !make tells the shell to run whatever the shell can fund under the name make . If you want to use VIM's makeprg , you need to use the VIM command :make .

Having said that, setting makeprg to sonething that is not a real make-style program is probably going to work only in the very simplest scenario.

You can run the compiler directly with !cl % . You need to put cl.exe in your PATH and probably set up other environment so that cl can find libraries and include files.

This is because you do not have the make executable installed, which is what vim is looking for. If you're looking to compile on the command line with make , I would recommend switching from the Visual Studio compiler to MinGW

make is a Unix tool, and while it is also available for Windows (in various flavors, native, Cygwin, or MinGW), it is usually not what you will be using together with MS Visual Studio.

It is difficult to be specific, since you told us nothing about the project you are trying to compile, but I will try.

If your project is set up as a Visual Studio solution, you can compile it using devenv :

devenv /build release mysolution.sln
devenv /build release /project mysolution/myproject/myproject.vcxproj

Your project might also be set up for NMake (which is a make-like tool shipping with MSVC):

nmake [target]

The two commands above require the current shell to be properly set up, which can be achieved by starting a "Visual Studio Command Line" from the start menu, or running %VS120COMNTOOLS%\\..\\..\\VC\\vcvarsall.bat from whatever shell you happen to work from. (Adjust VS120COMNTOOLS to whatever version of MSVC you are using.)

Or your project might actually be set up using "real" makefiles, in which case I second Levi: It seems like make is not installed, or has not been added to your PATH environment variable.

make [target]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM