如何在Visual Studio 2019 CMake项目中同时调试多个可执行文件?
How to Debug Multiple Executables (Server/Client) in Visual Studio 2019 CMake Project
Hey there, I’ve dealt with this exact setup before—here’s how to get VS2019 to launch both your server (exec1) and client (exec2) for simultaneous debugging:
- First, make sure the Solution node is visible in the Solution Explorer. If it’s hidden, go to
View > Solution Explorerto bring it up. - Right-click the root Solution node (not individual CMake targets) and select Properties from the context menu.
- In the Properties window, navigate to Common Properties > Startup Project in the left sidebar.
- Switch the radio button from Single startup project to Multiple startup projects.
- In the list below, locate both
exec1andexec2. For each, set their Action dropdown to Start. You can drag and reorder them if you need one to launch before the other (e.g., server first). - Click OK to save your changes.
Bonus: Customize Debug Settings for Each Executable
If you need to pass command-line arguments or tweak debug configurations for either program:
- Right-click the target (like
exec1) in the Solution Explorer under CMake targets. - Select Debug and Launch Settings—this will open a
launch.vs.jsonfile. - You can add args or adjust settings for each target here. For example:
{ "configurations": [ { "name": "exec1", "project": "CMakeLists.txt", "projectTarget": "exec1.exe", "args": ["--port", "8080"] }, { "name": "exec2", "project": "CMakeLists.txt", "projectTarget": "exec2.exe", "args": ["--server", "localhost"] } ] }
Once everything’s set up, hit the green Debug button—both your server and client will launch in separate debug sessions, and you can set breakpoints, inspect variables, and step through code in either one just like normal.
内容的提问来源于stack exchange,提问作者Jepessen
相关产品推荐
相关产品推荐

