Does anyone know how to use the command line compiler ('cl' and 'link') in Visual C++ to build a project? We are more used to 'make' and 'gcc' here, but were recently moved to Visual Studio. I suppose we could use nmake, but I'm hoping for some information regarding using 'cl' and 'link' (as in compiling without a .sln file).
something along the lines of
- create object files
- link object files to create executable
is what we want, but I just can't seem to make it work using the command line parameters. Help please?
Edit: sorry, didn't notice the 'without .sln' part. Ignore this answer please. I'm leaving it in place for others that may actually need this but it's not an answer to the original question.
If you just want to build a solution/project file (that is, most of your build settings are already defined in your project file), you can use
devenv.exe
to build the solution/project for you - this is probably the simplest way of doing a build from the command line.For example:
devenv.exe myapp.sln /Rebuild "Release|x64"
cleans & builds the
myapp.sln
solution in theRelease|x64
configuration.If you run
devenv.exe /?
command, it gives you all command-line options. You can use
devenv
to build only a specific project in the solution by using the `/project' switch.If you need more flexibility (and you're willing to spend a lot of time writing the right script), you can use
nmake
to build from the command-line, but I don't know that well, so I can't give useful advice.As I tend to always say, anything Microsoft related can be found on MSDN and a quick trip to google.
cl.exe is documented here: http://msdn.microsoft.com/en-us/library/ms235639%28v=vs.100%29.aspx
It's pretty simple just enter the directory of cl.exe and write in the cmd.
cl.exe /? and then it will list all the available flags.
You need to get 2 Files in you Path:
vcvarsall.bat is a shellscript which is responsible to determine on which architecture you're running on and includes several folders into your path which the cl compiler needs. on my pc this script resides under C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC
cl.exe is the compiler itself and on my pc resides under C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin
i simply declared a environment variable VC_HOME : C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC and included in the Path %VC_HOME%;%VC_HOME%\bin;
now when you open the shell, at first run vcvarsall.bat and then you can say: cl MyProgramm.cpp