windows 在 cmake/Visual Studio 项目中调试/运行可执行文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2630263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debugging/Running executables in cmake/Visual Studio project
提问by Paul
We are moving from hand-managed Visual Studio projects to cross platform cmake.
我们正在从手动管理的 Visual Studio 项目转向跨平台 cmake。
We used to open a solutions file, select a project as "Startup Target" and push Ctrl+F5 or F5 debug or run.
我们曾经打开一个解决方案文件,选择一个项目作为“启动目标”,然后按 Ctrl+F5 或 F5 调试或运行。
Now cmake has this install concept. It requires me to run the install target. But the install project doesn't have any executables set so it can not be used to start with debugging.
现在 cmake 有这个安装概念。它需要我运行安装目标。但是安装项目没有设置任何可执行文件,因此它不能用于开始调试。
If I set my executable project as a startup target, then install will not run, so I can not debug.
如果我将我的可执行项目设置为启动目标,那么安装将不会运行,因此我无法调试。
I am sure there is a better way of doing this.
我相信有更好的方法来做到这一点。
Any ideas ?
有任何想法吗 ?
回答by pkit
You should only need to run the INSTALL target if you want to distribute your application. If you select a project that builds an executable (so it has a ADD_EXECUTABLE statement in the CMakeLists.txt file) it should run with F5 or Ctrl+F5.
如果您想分发您的应用程序,您应该只需要运行 INSTALL 目标。如果您选择构建可执行文件的项目(因此它在 CMakeLists.txt 文件中有一个 ADD_EXECUTABLE 语句),它应该使用 F5 或 Ctrl+F5 运行。
It could be that you executable requires shared libraries which are build in a seperate directory. You can force all executables and libraries to be build in the same directory with the following CMake commands in your main CMakeLists.txt file.
可能是您的可执行文件需要在单独目录中构建的共享库。您可以使用主 CMakeLists.txt 文件中的以下 CMake 命令强制在同一目录中构建所有可执行文件和库。
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Library output path")
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Executable output path")
If you want more control over the command that should be run when debugging have a look at this question: How to Set Path Environment Variable using CMake and Visual Studio to Run Test
如果您想更多地控制调试时应运行的命令,请查看此问题:如何使用 CMake 和 Visual Studio 设置路径环境变量以运行测试