I'm trying to set up Vim to user VS (express) C compiler 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:
:! myfile.c >C:\Users\gvkv\AppData\Local\Temp\VIe7BF5.tmp 2>&1
and the loads myfile.c
into VS's IDE! Even if cl.exe
needs its environment:
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.
:se makeprg=gcc\ -o\ %<\ % and then use the vim make command to compile the current file and get a quickfixlist of errors in vim: :make EDIT: If you also want to run the compiled executable from within vim you can do ('!' executes]
For working with Java, I run :compiler javac (you're choosing the Vim file in that folder called javac.vim, not the command javac - although it will ultimately be used), and after that I can type :make % to compile my current Java file. % is essentially "the current file" to Vim.
Compiling C program with Visual Studio Code using Windows Compilation Compilation is a process of converting the source code into machine or object code. It is done with the help of the compiler. The compiler checks the source code for the errors, and if no error arises, then it generates the machine code.
There are several possibilities. Where the easiest Makefile would look like. Others can explain this a lot better. Show activity on this post. The canonical way to do this in Vim is to use the compiler configuration setting. Your vim installation almost certainly comes with a compiler plugin for gcc.
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. In particular
cl.exe
requires the correct environment as well as the correct path; i.e., adding C:\my\path\to\cl
isn't sufficient. Otherwise you will get errors reporting on missing DLL
s. The solution is to run vcvars32.bat
(or any other batch file which sets up a similar environment) and cl
as a single command.
cmd
requires any paths with spaces to be double quoted but you can't escape them with \
because :! ...
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
):
: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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With