C++ debugging on Windows
Debugging using Visual Studio
Build 3D Slicer in Debug by following the build instructions.
To run Slicer, the launcher needs to set certain environment variables. The easiest is to use the launcher to set these and start Visual Studio in this environment. All these can be accomplished by running the following command in
If you just want to start VisualStudio with the launcher (and then load project file manually), run:
To debug an extension that builds third-party DLLs, also specify
While you can launch debugger using Slicer’s solution file, it is usually more convenient to load your extension’s solution file (because your extension solution is smaller and most likely you want to have that solution open anyway for making changes in your code). For example, you can launch Visual Studio to debug your extension like this:
.\SD\Slicer-build\Slicer.exe --VisualStudio --launcher-no-splash --launcher-additional-settings ./SlicerRT_D/inner-build/AdditionalLauncherSettings.ini c:\d\_Extensions\SlicerRT_D\inner-build\SlicerRT.sln
In Solution Explorer window in Visual Studio, expand
App-Slicer, right-click on
SlicerApp(NOT qSlicerApp) and select “Set as Startup Project”
To debug in an extension’s solution: set
ALL_BUILDproject as startup project and in project settings, set
Commandfield to the full path of
SlicerApp-real.exe- something like
Run Slicer in debug mode by Start Debugging command (in Debug menu).
Note that because CMake re-creates the solution file from within the build process, Visual Studio will sometimes need to stop and reload the project, requiring manual button pressing on your part (just press Yes or OK whenever you are asked). To avoid this, you can use a script to complete the build process and then re-start the Visual Studio.
For more debugging tips and tricks, check out this page.
Once VisualStudio is open with the Slicer environment loaded, it is possible to run and debug tests. See general information about running tests here. Specific instructions for Visual Studio:
To debug a test, find its project in the Solution explorer tree.
Make the project the startup project (right-click -> Set As Startup Project).
Specify test name and additional input arguments:
Go to the project debugging properties (right click -> Properties, then Configuration Properties/Debugging)
Command Arguments, type the name of the test (e.g.
MRMLCoreCxxTests) followed by additional arguments (if any).
Start debugging by choosing
Start debuggingin Edit menu.
To run all tests, build the
Debugging using cross-platform IDEs
On Windows, Visual Studio is the most feature-rich and powerful debugger, but in case somebody wants to use cross-platform tools then these instructions may help: