Visual Studio: how to create a project that would compile 2 exe files?

Rella picture Rella · Jan 23, 2011 · Viewed 22.8k times · Source

So I have main.cpp and main2.cpp with int main in each. I want to get 2 exes out of it. Is it possible and what would be instruction to create such project?

Answer

jalf picture jalf · Jan 23, 2011

Nope, Visual Studio's project model is rigidly built around the assumption that "one project generates one output".

If you need two executables, you have to create two projects. You can keep them in the same solution to make things easier for yourself, but they have to be separate projects.

Edit
Ok, as other answers have pointed out, it can of course be done, if you're desperate. You can add a custom build step, which does anything you like, including building another executable. (However, the build system won't understand that this file should be considered project output, and so some scenarios may fail: for example the file won't be automatically copied to the output folder, and when checking dependencies before a rebuild, it might not be able to understand which files to check, and what (or how) to rebuild.)

Visual Studio (at least up to 2008, not sure about 2010) also allows the use of nmake files, but then I think you're stretching the definition of "a Visual Studio project".

But under "normal" circumstances, one project implies one output. And in order to get two executables, you'd normally create two projects.