从CMake创建Visual Studio项目,Visual Studio无法找到可执行文件。

3
基本上,我的问题与如何配置CMake,以便生成的Visual Studio项目可以找到可执行文件?相同。那里的任何答案都对我没有用。
我有一个CMake项目,我只想从中创建一个Visual Studio 2019项目:
  • So I just run cmake . from the root directory.
  • Then I have a *.sln file in my root directory.

  • After opening it with Visual Studio 2019, I press the "Local Widows Debugger" button, it compiles successfully but then the IDE complains with:

    Unable to start program 'C:\Users...\x64\Debug\ALL_BUILD'. The system is unable to find the specified file.
    
使用travis一切都编译得很好,链接如下:https://travis-ci.com/Necktschnagge/markov_chain_analyzer/builds/144941090 你可以在这里查看代码:https://github.com/Necktschnagge/markov_chain_analyzer/tree/old 我需要做什么才能让CMake创建一个良好配置的VS解决方案,以便我可以运行调试器?

1
现代的Visual Studio版本已经直接集成了CMake:https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019,因此现在您可以绕过所有这些步骤。 - user4442671
1
通常情况下,您不会启动“all_build”项目。 - Michael Chourdakis
1个回答

10
当你使用CMake创建Visual Studio解决方案时,它会自动将启动项目设置为ALL_BUILD。这是一个CMake预定义的目标,它构建解决方案中的所有项目。它不是包含可调试可执行文件的项目。
在调试之前,您必须在Solution Explorer中将启动项目更改为其中一个可执行项目。您可以通过右键单击要调试的项目,然后选择Set as Startup Project来完成此操作。如果您正在使用VS与CMake集成,则还有一些更多的说明here
您还可以通过使用VS_STARTUP_PROJECT告诉CMake在从头开始构建CMake时默认设置不同的启动项目。在您的顶级CMake文件中放置类似以下内容的东西:
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT MyExeTarget)

现在,CMake会将MyExeTarget设置为Visual Studio中的启动项目,而不是ALL_BUILD

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接