Visual Studio: how to create a project that would compile 2 exe files?(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.
这篇关于Visual Studio:如何创建一个可以编译 2 个 exe 文件的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Visual Studio:如何创建一个可以编译 2 个 exe 文件的项目?
基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 从 std::cin 读取密码 2021-01-01