How can I compile a C / C ++ file in Windows 8 using VS2012 from the console?

For example, such:

// main.cpp #include <iostream> using namespace std; int main() { cout << "Hello" << endl; } 

There is no desire to put MinGW or Cygwin, because the compiler is already there (it’s in Visual Studio).

UPD:
First, in the console from the folder C: \ Program Files (x86) \ Microsoft Visual Studio 11.0 \ VC \ bin run the file vcvars32.bat

Then use:

 cl main.cpp 

All sorts of keys for the compiler: Compiler Options Listed by Category

  • >> C / C ++ file Where is the C file here? - skegg
  • the question is, not how to compile a specific file, but how to compile a file from a console that uses only STL. For example, as in Linux, g ++ main.cpp -o main - Ildik Simpson
  • msdn.microsoft.com/en-us/library/ms235639(v=vs.80).aspx cl.exe is located in the Visual Studio 2012 \ VC \ bin folder igumnov


1 answer 1

In VS2010, XP does this

 cl main.cpp /Feprog_name 
  • 2
    Wonderful. Only (I don’t know about 2010) in older ones, it was necessary to set the necessary variables (path, etc.). And VS somewhere put a specially created batch file with these settings. Toli VSVARS.BAT, or even some. - alexlz
  • So VS provides its command line, where all variables are already set. If you want to use a regular line, you can either register the paths or write cl with the path directly in the line: c: \ Program Files \ ... \ cl - skegg
  • 2
    Even if you run cl directly, swears at the missing mspdb100.dll. Accordingly, to it (and most likely to other libraries) the path should also be registered. After performance of vcvars32.bat ceases to swear. - insolor
  • So you can throw this dll in the folder with the executable. - skegg
  • It unless if suddenly it is required to collect the portable version of the compiler from MS. And so there is a PATH - insolor