# Compile time is very long -- how to optimize?

**URL:** https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196
**Category:** Beginner Questions
**Tags:** cmake, make
**Created:** [July 18, 2022, 7:46pm UTC](https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196 "2022-07-18T19:46:19Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![gmm9uf](https://discourse.itk.org/user_avatar/discourse.itk.org/gmm9uf/32/2810_2.png) [@gmm9uf](https://discourse.itk.org/u/gmm9uf)
#### Post date: [July 18, 2022, 7:46pm UTC](https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196/1 "2022-07-18T19:46:20Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [July 18, 2022, 7:53pm UTC](https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196/2 "2022-07-18T19:53:01Z")

</div>

That is not normal even for very large projects. How did you set up your build system? Using [`ninja`](https://ninja-build.org/) instead of `make` might help with build times.

---

<div class="post-metadata">

### Author: ![gmm9uf](https://discourse.itk.org/user_avatar/discourse.itk.org/gmm9uf/32/2810_2.png) [@gmm9uf](https://discourse.itk.org/u/gmm9uf)
#### Post date: [July 19, 2022, 10:12am UTC](https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196/3 "2022-07-19T10:12:49Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [July 19, 2022, 4:17pm UTC](https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196/4 "2022-07-19T16:17:11Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Lee\_Newberg](https://discourse.itk.org/user_avatar/discourse.itk.org/lee_newberg/32/1461_2.png) [@Lee\_Newberg](https://discourse.itk.org/u/Lee_Newberg)
#### Post date: [July 19, 2022, 4:40pm UTC](https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196/5 "2022-07-19T16:40:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![gmm9uf](https://discourse.itk.org/user_avatar/discourse.itk.org/gmm9uf/32/2810_2.png) [@gmm9uf](https://discourse.itk.org/u/gmm9uf)
#### Post date: [July 19, 2022, 8:33pm UTC](https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196/6 "2022-07-19T20:33:31Z")

</div>

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?)

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [July 19, 2022, 9:14pm UTC](https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196/7 "2022-07-19T21:14:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gmm9uf](https://discourse.itk.org/user_avatar/discourse.itk.org/gmm9uf/32/2810_2.png) [@gmm9uf](https://discourse.itk.org/u/gmm9uf)
#### Post date: [July 26, 2022, 3:32pm UTC](https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196/8 "2022-07-26T15:32:13Z")

</div>

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

 ![image](https://discourse.itk.org/uploads/default/original/2X/8/8e13c05f5de39675332b6771a1208303b5cac333.png)  
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.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [July 26, 2022, 4:03pm UTC](https://discourse.itk.org/t/compile-time-is-very-long-how-to-optimize/5196/9 "2022-07-26T16:03:43Z")

</div>

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.
