问题
I'm using CMake for a C++ project. I'm trying to use profile guided optimization so I need to also pass command line arguments to the Release mode version of my binary. Visual Studio needs this to create a performance profile. I already have a launch.vs.json configuration for the Debug mode binary with command line arguments:
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"name": "MyProject",
"project": "CMakeLists.txt",
"projectTarget": "MyProject.exe",
"type": "default",
"args": [
"...", "..."
]
}
]
}
When I switch to Release mode and choose the MyProject startup item, Visual Studio shows the following error message:
Unable to start debugging. The startup project could not be launched.
Why does it not work that way? I also cannot setup another profile and make Visual Studio recognize it in Release mode but it works fine in Debug mode.
回答1:
I managed to do it now by adding another entry:
{
"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": ["...", "..."]
}
]
}
来源:https://stackoverflow.com/questions/53726905/passing-command-line-arguments-to-visual-studio-using-cmake-for-profile-guided-o