# Long path using ninja

**URL:** <https://discourse.slicer.org/t/long-path-using-ninja/1702>\
**Category:** Development\
**Created:** [December 21, 2017, 3:08pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702 "2017-12-21T15:08:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [December 21, 2017, 3:08pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/1 "2017-12-21T15:08:40Z")

</div>

Configuring Slicer with **ninja** as the make program, and VS2015 cl.exe as compiler, I run into the error below. This doesn’t happen with pure VS2015 build in one letter longer build dir (`C:/Dev/Sn/` vs `C:/Dev/Svs/`). Is ninja merely more careful, or is this specific to ninja?

```auto
CMake Warning in Modules/Loadable/VolumeRendering/SubjectHierarchyPlugins/CMakeLists.txt:
  The object file directory

    C:/Dev/Sn/Slicer-build/Modules/Loadable/VolumeRendering/SubjectHierarchyPlugins/CMakeFiles/qSlicerVolumeRenderingSubjectHierarchyPluginsPythonQt.dir/

  has 149 characters. The maximum full path to an object file is 250
  characters (see CMAKE_OBJECT_PATH_MAX). Object file

    generated_cpp/osm_qSlicerVolumeRenderingSubjectHierarchyPlugins/osm_qSlicerVolumeRenderingSubjectHierarchyPlugins_module_init.cpp.obj

  cannot be safely placed under this directory. The build may not work
  correctly.

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 21, 2017, 3:13pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/2 "2017-12-21T15:13:05Z")

</div>

This is a warning only. Probably you just haven’t noticed it when you’ve built Slicer with the default generator.

---

<div class="post-metadata">

**Author:** ![msmolens](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/msmolens/32/139_2.png) [@msmolens](https://discourse.slicer.org/u/msmolens)\
**Post date:** [December 21, 2017, 3:32pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/3 "2017-12-21T15:32:50Z")

</div>

On a related note, has anyone tried enabling the new long path behavior in Windows 10?

From [Naming Files, Paths, and Namespaces - Win32 apps | Microsoft Learn](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath:)

> Starting in Windows 10, version 1607, MAX\_PATH limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behavior.  
> …  
> To enable long path behavior set the registry key at HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled (Type: REG\_DWORD).

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [December 21, 2017, 4:00pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/4 "2017-12-21T16:00:45Z")

</div>

> [@lassoan](#):
>
> This is a warning only.

The build stopped soon afterwards. I am now re-running ninja to see what happens.

> [@msmolens](#):
>
> has anyone tried enabling the new long path behavior in Windows 10

I could try it at home!

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [December 21, 2017, 4:03pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/5 "2017-12-21T16:03:09Z")

</div>

After re-running ninja, I get the same error:

```auto
-- Configuring done
CMake Warning in Modules/Loadable/VolumeRendering/SubjectHierarchyPlugins/CMakeLists.txt:
  The object file directory

    C:/Dev/Sn/Slicer-build/Modules/Loadable/VolumeRendering/SubjectHierarchyPlugins/CMakeFiles/qSlicerVolumeRenderingSubjectHierarchyPluginsPythonQt.dir/

  has 149 characters. The maximum full path to an object file is 250
  characters (see CMAKE_OBJECT_PATH_MAX). Object file

    generated_cpp/osm_qSlicerVolumeRenderingSubjectHierarchyPlugins/osm_qSlicerVolumeRenderingSubjectHierarchyPlugins_module_init.cpp.obj

  cannot be safely placed under this directory. The build may not work
  correctly.

-- Generating done
-- Build files have been written to: C:/Dev/Sn/Slicer-build
[214/217] Performing build step for 'Slicer'
FAILED: Slicer-prefix/src/Slicer-stamp/Slicer-build
cmd.exe /C "cd /D C:\Dev\Sn\Slicer-build && "C:\Program Files\CMake\bin\cmake.exe" --build . && "C:\Program Files\CMake\bin\cmake.exe" -E touch C:/Dev/Sn/Slicer-prefix/src/Slicer-stamp/Slicer-build"
ninja: build stopped: subcommand failed.

C:\Dev\Sn>

```

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [December 22, 2017, 2:42am UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/6 "2017-12-22T02:42:03Z")

</div>

Trying to build Slicer in a long path build directory, the build fails when it comes turn to configure ITK. Then it snowballs from there. I guess we need to add extra logic to this check to handle the possibility of longer paths which now exists in Windows.

```auto
50> CMake Error at CMakeLists.txt:30 (message):
50> ITK source code directory path length is too long (65 > 50).Please move the
50> ITK source code directory to a directory with a shorter path.
50>
50>
50> -- Configuring incomplete, errors occurred!
50> See also "C:/Dev/Slicer-buildVS2015x64-super-long-path-without-spaces/ITKv4-build/CMakeFiles/CMakeOutput.log".

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 22, 2017, 3:23am UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/7 "2017-12-22T03:23:48Z")

</div>

> [@msmolens](#):
>
> On a related note, has anyone tried enabling the new long path behavior in Windows 10?

It’ll take several years until all build tools will be updated to take advantage of new file path lengths. Also note that often long paths cause build failures by making environment variables too long.

It would be easier to limit file and directory name lengths in VTK and ITK. File path length issues popped up when modularization was introduced in VTK and ITK: it added one more level of directory for all files and increased number of libraries by a factor of 10x - which threw off Visual Studio.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [December 23, 2017, 7:08pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/8 "2017-12-23T19:08:10Z")

</div>

Refactoring has already been done, and there is no going back. The support for longer max path was just [added](https://discourse.itk.org/t/path-length-limitation-in-windows-lifted/545) to ITK.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 23, 2017, 8:32pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/9 "2017-12-23T20:32:09Z")

</div>

Modularization is good, I’m not suggesting to going back, but it is implemented in a way that it puts significant burden on build systems. Hopefully, ITK&VTK build system and/or Visual Studio will be improved at some point, because in large projects like Slicer we are near the limit of having a feasible build.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [December 26, 2017, 4:32pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/10 "2017-12-26T16:32:13Z")

</div>

VTK developers plan to overhaul their build system. Once they are done, we plan to plagiarize that for ITK.

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [December 26, 2017, 4:37pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/11 "2017-12-26T16:37:58Z")

</div>

Do you mind to link to the discussion, if available?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [December 26, 2017, 8:35pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/12 "2017-12-26T20:35:41Z")

</div>

I wanted to, but I don’t remember where I saw that.

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [December 27, 2017, 2:36pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/13 "2017-12-27T14:36:47Z")

</div>

We could make various changes to use the modularized build more effectively (e.g. not passing the full paths to every single library). But we effectively dump all VTK\_LIBRARIES to the linker anyway, so modularization was kind of a no-op and comes at the cost of startup time. Processing \>600 dynamic libraries is really slow on mac (and to a lesser degree linux): a debug build takes close to 1 min to start on mac, the majority of which is in `strcmp` during symbol relocations. Release build is somewhat faster of course, but still spends most time doing relocation.

(Apple’s code dump for 10.13 shows big changes in dyld including some files about “caching”, so maybe this improves in High Sierra – but I still haven’t upgraded)

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [December 27, 2017, 4:21pm UTC](https://discourse.slicer.org/t/long-path-using-ninja/1702/14 "2017-12-27T16:21:39Z")

</div>

Just to clarify, that comment was intended as an observation rather than a complaint per se 🙂. There is enough other low-hanging fruit to go after next time we do build system optimization, and in the worst case we can relink VTK and ITK into single libraries ourself if it is demonstrably faster.
