在cmake / Visual Studio项目中调试/运行可执行文件 [英] Debugging/Running executables in cmake/Visual Studio project

查看:254
本文介绍了在cmake / Visual Studio项目中调试/运行可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正从手工管理的Visual Studio项目转移到跨平台cmake。

We are moving from hand-managed Visual Studio projects to cross platform cmake.

我们用来打开一个解决方案文件,选择一个项目作为启动目标按Ctrl + F5或F5调试或运行。

We used to open a solutions file, select a project as "Startup Target" and push Ctrl+F5 or F5 debug or run.

现在cmake有这个安装概念。它需要我运行安装目标。但是安装项目没有设置任何可执行文件,因此不能用于开始调试。

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.

如果我将可执行项目设置为启动目标,不会运行,所以我不能调试。

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.

任何想法?

推荐答案

如果要分发应用程序,您只需运行INSTALL目标。如果选择一个构建可执行文件的项目(因此它在CMakeLists.txt文件中有一个ADD_EXECUTABLE语句),它应该使用F5或Ctrl + F5运行。

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.

是可执行的,需要在一个单独的目录中构建的共享库。您可以强制所有可执行文件和库在主CMakeLists.txt文件中使用以下CMake命令在同一目录中构建。

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.

   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")

如果你想更多地控制应该在调试时运行的命令,看看这个问题: a href =http://stackoverflow.com/questions/1005901/how-to-set-path-environment-variable-using-cmake-and-visual-studio-to-run-test/1307784#1307784>如何使用CMake和Visual Studio设置路径环境变量运行测试

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项目中调试/运行可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆