How to compile and run the files.

my build is completed just now, now I have two folders one contains the repository cloned file and another one contains the build files, the build folder now has a lot more folders, now I am totally confused that in which directory I have to change the source code??
and let’s suppose I changed some code in a file then how can I see the reflection of it? by building it again or what commands should I use to compile the whole file or what is the procedure because till now I’ve worked with only one or two c++ files which I simply compile and run, but here I have no clue.

Hello @Arun03Kumar.

Directly modifying 3D Slicer can be overwhelming and may not always be sustainable. Given the fast-paced development of the main repository, your changes might not align with the ongoing updates, making them challenging to integrate.

Perhaps a better approach would be to explore development through extensions. Extensions allow you to add functionality to 3D Slicer without altering the core codebase of 3D Slicer. This method ensures (to a large degree) your work remains compatible with future updates of 3D Slicer and is easier to manage. You can get more information in the extensions documentation

However, if you still wish to modify the core code, remember that the repository you cloned is where you make changes. Your build directory is for compiled files and shouldn’t be modified for code changes. After editing the source code in the repository, return to the build directory and recompile to see your changes. The developer guide will help you understand the structure of the project.

I hope this helps.

1 Like

Thank you so much @RafaelPalomar.

so if I want to change some thing then I’ll change in the source directory, then go back to my build directory and just run “cmake --build” in build directory. then run the slicer.exe from slicer-build folder to see the changes.
is this the correct process or should I have to do something else??
can you please elaborate in step by step manner, till now I have just compiled only single c++ file using gcc command.

Thank you.

That’s correct. The cmake build command may require specification of a directory i.e., cmake --build ..

3D Slicer uses the CMake build system to manage the project. Manually compiling individual files is not a good idea, introducing changes require updating the project output in a wider manner. You can refer to the CMake documentation to understand the workflow used in CMake-based projects.

1 Like

okay, thank you. :+1:

I tried to recompile the source after a small change with 'cmake --build ." command in SD folder which is build folder as specified on slice build documentation, but it still took the same time to build (around 9 hours).

I am not following that if I change something then should I have to wait until the next build.

or you just please the steps involved in compiling and seeing the output after a change in source directory.

my directory structure is same as specified on github build documentation
source - "C:/D/S
debug build - "C:/D/SD/

Hi @Arun03Kumar,

Slicer’s build system works with a superbuild, meaning that the “C:/D/S” folder contains both Slicer’s build tree and Slicer’s dependencies build trees.

After the first build, if you want to build only Slicer, you can navigate to the “C:/D/S/Slicer-build” dir and build only this one.

Note also that Slicer is modularized which can help if you want to build only the target you have modified (which will be much faster).

Best,
Thibault

1 Like

Building 3D Slicer implies building many of its dependencies. You can improve the building time of Slicer (first-time, but also subsequent builds by the use parallel jobs i.e., cmake --build -j9 where 9 was the number of parallel jobs). The rule of thumb is to use number_of_threads+1, but there is absolutely no science behind it and depends on what you build. In addition increasing the number of parallel jobs, generally, increases the memory required (if you go above, your computer can “freeze” while compiling). More info at GNU/Linux systems — 3D Slicer documentation