Compile time is very long -- how to optimize?

I am using cmake and make to build and compile C++ code on a linux interface. Each time I want to modify the code and recompile (i.e., make), it takes about 20 minutes to recompile using make. Does anyone know why this would be happening or how to optimize this – or is this expected, and there are no known solutions?

That is not normal even for very large projects. How did you set up your build system? Using ninja instead of make might help with build times.

I set up my build system using cmake – is that what you mean by how did I set it up? I am running Ubuntu/WSL via MobaXTerm (a linux terminal for a Windows machine). I would try ninja, but first I’m not sure why this is going as slowly as it is, and I’m maybe something else is going wrong?

If I remember correctly, WSL does not have great performance with filesystem operations. And compiling involves a lot. Can you try how well it works on pure Linux or pure Windows?

1 Like

Twenty minutes is high but it isn’t crazy high – if you are requesting Python wrapping or other add ons. Are you?

Trying ninja should help and it’s easy to do. I use a cmake command line; add -GNinja when you are configuring as in cd ITK-build; cmake -DCMAKE_BUILD_TYPE:STRING=Debug all_your_other_flags -GNinja ../ITK or similar. Then build as usual with cmake --build . or something similar. You may need to install ninja first, of course.

2 Likes

Thank you for the comments! I am not requesting Python wrapping or any add ons – I am only coding in C++, so maybe it’s just because I’m running it on WSL? I will try building ITK using ninja and see if it helps – if not I will try cmake-gui on windows (perhaps via Visual Studios if people have better luck with that?)

I usually use CMake-GUI on Windows, and generate Visual Studio project files. That works well.

1 Like

When I run cmake-gui and try to generate a Visual Studio (VS) project file, there is no VS generator available:


Is the generator something that I should separately download? I apologize for the simple question but just haven’t found any information on this online.

I was under the impression that you use Windows. I think that Visual Studio doesn’t even have to be installed to generate projects for it. There has to be C and C++ compilers available.

There is no Visual Studio for Linux, so it looks like there is no generator for it in Linux version of CMake either.

1 Like