Visual Studio:如何创建一个将编译2个exe文件的项目?

Visual Studio:如何创建一个将编译2个exe文件的项目?

问题描述:

所以我有main.cpp和main2.cpp与int main在每个。我想得到2 exes从它。

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?

没有,Visual Studio的项目模型是围绕这个假设一个项目生成一个输出。

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.

编辑
$您可以将它们保存在同一个解决方案中, b $ b Ok,正如其他答案所指出的,它当然可以做,如果你绝望。您可以添加自定义构建步骤,它可以执行任何您喜欢的操作,包括构建另一个可执行文件。 (但是,构建系统不会理解这个文件应该被视为项目输出,因此一些情况可能会失败:例如,文件不会自动复制到输出文件夹,并且在重建之前检查依赖关系时,可能无法了解要检查的文件以及要重建的内容(或如何重建)。

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(至少到2008年,不确定2010年)也允许使用nmake文件,但后来我想你正在拉伸Visual Studio项目的定义。

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.