使用CMake将命令行参数传递给Visual Studio进行配置文件引导的优化

时间:2018-12-11 15:04:09

标签: c++ visual-studio cmake release

我正在将CMake用于一个C++项目。我正在尝试使用profile guided optimization,因此还需要将命令行参数传递给二进制文件的Release模式版本。 Visual Studio需要使用它来创建性能配置文件。我已经为launch.vs.json模式二进制文件提供了Debug配置,并带有命令行参数:

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "name": "MyProject",
      "project": "CMakeLists.txt",
      "projectTarget": "MyProject.exe",
      "type": "default",
      "args": [
        "...", "..."
      ]
    }
  ]
}

当我切换到Release模式并选择MyProject启动项时,Visual Studio显示以下错误消息:

Unable to start debugging. The startup project could not be launched.

为什么它不能那样工作?我也无法设置其他配置文件并使Visual StudioRelease模式下能够识别它,但是在Debug模式下它可以正常工作。

1 个答案:

答案 0 :(得分:0)

我现在设法通过添加另一个条目来做到这一点:

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "name": "MyProject",
      "project": "CMakeLists.txt",
      "projectTarget": "MyProject.exe",
      "type": "default",
      "args": ["...", "..."]
    },
    {
      "name": "MyProject (Release\\MyProject.exe)",
      "project": "CMakeLists.txt",
      "projectTarget": "MyProject.exe (Release\\MyProject.exe)",
      "type": "default",
      "args": ["...", "..."]
    }
  ]
}