Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling on the command line in Visual C++

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

  1. create object files
  2. 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?

like image 708
Raven Knit Avatar asked Mar 22 '12 01:03

Raven Knit


2 Answers

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.

like image 167
Aleks Avatar answered Nov 16 '22 19:11

Aleks


You need to get 2 Files in you Path:

  • vcvarsall.bat
  • cl.exe

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

like image 3
martyglaubitz Avatar answered Nov 16 '22 21:11

martyglaubitz