6

I have VS Express (2012) for Desktop. Am I also acquired the NMAKE.EXE program?

http://msdn.microsoft.com/en-us/library/dd9y37ha.aspx - The Microsoft Program Maintenance Utility (NMAKE.EXE) is a tool that builds projects based on commands contained in a description file.

When I run :make after running :compiler msvc, the shell returned the message 'nmake' is not recognized as an internal or external command,”. How can I compile a C++ program using these commands? Does the tool NMAKE.EXE have a relation to the 'nmake' command?


http://msdn.microsoft.com/en-us/library/wea2sca5(v=vs.90).aspx - MSBuild is the new build platform for Microsoft and Visual Studio.

http://msdn.microsoft.com/en-us/library/dd293626.aspx - You can use the MSBuild tool to build a Visual C++ application from the command prompt. The build process is controlled by the information in a project file (.vcxproj) that you can create and edit. The project file specifies build options based on build stages, conditions, and events.

Did I also acquired the MSBuild tool because of my VS Express for Desktop? When I use :make after running :compiler msbuild, the shell returned the message “'msbuild' is not recognized as an internal or external command,”. Does msbuild.vim have a relation to MSBuild tool?

The maintainer of msbuild.vim said, “I made the script for compiling C# projects using .NET... I don't know if it will work for C++...”

How can I be able to compile by running :compiler msbuild before :make in Vim?


There are only two questions about compiling a program such as a C++ source file, on this question, and please answer with detailed instructions:

  1. How to use :compiler msvc?
  2. How to use :compiler msbuild?
5ervant
  • 3,928
  • 6
  • 34
  • 63
  • 1
    Try running (g)VIM from a "Visual Studio (2012) Command Prompt" (should be available in your start menu/screen) – user786653 Sep 09 '13 at 19:09
  • Another information at http://vim.wikia.com/wiki/Integrate_gvim_with_Visual_Studio#Compiling_from_Vim that could help to solve this question said _“If you use nmake, you can use `compiler msvc` to set Vim's `errorformat` and `makeprg` for Visual C++. Use `compiler cs` for C#.”_ – 5ervant Sep 14 '13 at 06:55

2 Answers2

5

A quick search came across this: Getting started - C/C++ programming with VIM, which may be a good starting point.

As user786653 mentioned, this is failing because your PATH doesn't include the directory nmake.exe is in. You can inspect your path with

:echo $PATH 

Vim doesn't replace the underlying build functionality, it simply wraps it.

  1. Start gVim from the Visual Studio command prompt
  2. Create new files in a test directory:

    test.cpp

    #include <iostream>
    int main() { 
        printf("hello world.");
        return 0;
    }
    

    Makefile

    all:
        cl test.cpp 
    
  3. set the compiler (gVim)

    :compiler msvc
    
  4. compile (gVim)

    :make
    

I don't have the msbuild.vim script, but by setting the "make program" to msbuild.exe

:set makeprg=msbuild

you can build, by running :make from a directory containing a solution (.sln) or project (.vxcproj) file, or you can use the msbuild.exe command line like this:

:make c:\Test\Test.sln  /t:Rebuild /p:Configuration=Debug

After compiling, you can examine the output with

:copen 

and navigate the errors with (n for next, p for previous, and r for rewind to the first error)

:cn 
:cp 
:cr 
g3cko
  • 860
  • 1
  • 6
  • 20
  • I already tried running (g)Vim from the Developer Command Prompt for VS2012. I think the right instructions would make it work. – 5ervant Sep 14 '13 at 06:40
  • The shell returned _“MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.”_ when `:compiler msbuild` is used. Your answer about `:compiler msvc` is working but it's not well instructed, specially for a beginner. It doesn't even have any macro. And most of all, I spend days to read all the contents under [NMAKE Reference](http://msdn.microsoft.com/en-us/library/dd9y37ha.aspx). Yet, I think this answer deserve to be awarded half the bounty amount. – 5ervant Sep 20 '13 at 07:26
  • 1
    Ah, that's a good point, I didn't mention that the current directory needs to include a solution (.sln) or project (.vxcproj) file, much like it does for the makefile. I'll edit that to be more clear. – g3cko Sep 20 '13 at 22:36
  • Your answer have no guide about _Makefile_. The command on it doesn't even include command-line option. And there have no macro. No guide or even a sample of project or solution file. Yet, you know what you're doing and it gives complete ideas.. – 5ervant Sep 21 '13 at 13:57
  • 1
    Using makefiles, and compiling code in general seem like a separate layer to understand, with vim being a thin layer on top of that. Here's a reference I found, which may be helpful. http://stackoverflow.com/questions/2481269/how-to-make-simple-c-makefile – g3cko Oct 01 '13 at 18:36
5

When I use :make after running :compiler msbuild, the shell returned the message “'msbuild' is not recognized as an internal or external command,”. Does msbuild.vim have a relation to MSBuild tool?

Yes.

To enable msbuild in Command Prompt, you simply have to add the path to the .net4 framework install on your machine to the PATH environment variable. The following worked for me on Windows:

You can access the environment variables by right clicking on 'Computer', click 'properties' and click 'Advanced system settings' on the left navigation bar. On the next dialog bog click 'Environment variables,' scroll down to 'PATH' and edit it to include your path to the framework (don't forget a ';' after the last entry in here.

For reference my path was C:\Windows\Microsoft.NET\Framework64\v4.0.30319. [1]

Though I only use it for C# projects, I suppose it will work for C++ as well. Remember that you have to run msbuild inside the project directory, otherwise msbuild will not be able to find your project.

For the sake of completeness, here a snippet of my vimrc (which the OP already got by email).

noremap <F4> :<C-U>silent make<CR>:redraw!<CR>
au FileType cs compiler msbuild

Patches and additions to this compiler script are always welcome, of course!

Regards

[1]: How do I run msbuild from the command line using Windows SDK 7.1?

Community
  • 1
  • 1
Chiel ten Brinke
  • 12,091
  • 12
  • 60
  • 104
  • It took me awhile before I got notice that this answer was came from the maintainer of **msbuild.vim** _(Microsoft Visual Studio C#)_ script. – 5ervant Sep 21 '13 at 13:15
  • Usually I use xbuild (the mono equivalent of msbuild) on Linux. In order to answer this question I installed vim on windows and added msbuild to my path using the above method. Opening a source file and running `:comp msbuild` and `:make` immediately made the project compile. – Chiel ten Brinke Sep 21 '13 at 13:56
  • I don't know yet. In this time I'm not in focus about this topic. But I think after setting the path, it's required to specify a project _(.vcxproj)_ or solution _(.sln)_ file to make a program compile. If this didn't work then I think a makefile is also needed. Actually I don't have yet the capacity to understand the first line on your snippet _(but I can review it)_. – 5ervant Sep 22 '13 at 13:21
  • @Chiel ten Brinke : if I run `:compiler msbuild`, get the following error: `Error detected while processing ...vim81\compiler\msbuild.vim: line 18: E518: Unknown option: /nologo\ /v:q\ /property:GenerateFullPaths=true` Can you tell me how to fix it? The error comes in neovim too :( – Mattia72 Apr 16 '19 at 07:11