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

所以我有 main.cpp 和 main2.cpp,每个都有 int main.我想从中获取 2 个 exe.是否有可能创建这样的项目?有什么说明?

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.

编辑
好的,正如其他答案所指出的那样,如果您不顾一切,当然可以做到.您可以添加自定义构建步骤,它可以执行您喜欢的任何操作,包括构建另一个可执行文件.(但是,构建系统不会理解这个文件应该被视为项目输出,因此某些情况可能会失败:例如文件不会自动复制到输出文件夹,并且在重建之前检查依赖项时,它可能无法理解要检查哪些文件,以及要重建什么(或如何).

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.

相关文章