4

I have a lot of files - examples code in C++. I open every file and I must copy code from example file to main.cpp file in some project. Can Visual studio compile one opened file in .cpp without project?

user1779502
  • 573
  • 2
  • 8
  • 16
  • You go back to an ancient copy of VS (6.0 or earlier), or live without. Technically, even then you needed a project -- but if you asked it to compile without a project, it would create one automatically, then compile. Might have added an extra .1 second to the compile cycle, but was otherwise fairly transparent. Now, VS is built with the idea that you need to do things its way, not to support doing what you want. – Jerry Coffin Nov 03 '12 at 15:15

2 Answers2

5

It's probably easiest to compile from the command line in this case.

Start a Command Prompt window and run the batch file to set up the environment variables (%PATH% etc.) appropriately. On my PC this is

"C:\Program Files\Microsoft Visual Studio 9.0\vc\vcvarsall.bat"

Then to compile foo.cpp into foo.exe, just use

cl /EHsc foo.cpp
j_random_hacker
  • 50,331
  • 10
  • 105
  • 169
1

Visual Studio includes a compiler and linker which can be run from the command line. This might give you some pointers. I think you'll find it easier to create a project though. Can't you just create one project and reuse it?

Community
  • 1
  • 1
john
  • 85,011
  • 4
  • 57
  • 81