# How to build 3D Slicer for Raspberry?

**URL:** <https://discourse.slicer.org/t/how-to-build-3d-slicer-for-raspberry/2843>\
**Category:** Support\
**Created:** [May 17, 2018, 3:19pm UTC](https://discourse.slicer.org/t/how-to-build-3d-slicer-for-raspberry/2843 "2018-05-17T15:19:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AhmadHossam10](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ahmadhossam10/32/1246_2.png) [@AhmadHossam10](https://discourse.slicer.org/u/AhmadHossam10)\
**Post date:** [May 17, 2018, 3:19pm UTC](https://discourse.slicer.org/t/how-to-build-3d-slicer-for-raspberry/2843/1 "2018-05-17T15:19:20Z")

</div>

How to build slicer on raspberri Pi having rasbpian OS?

---

<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:** [May 17, 2018, 3:54pm UTC](https://discourse.slicer.org/t/how-to-build-3d-slicer-for-raspberry/2843/2 "2018-05-17T15:54:13Z")

</div>

Follow Linux [build instructions](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Build_Instructions). Complete build takes several hours on a desktop PC, so on a raspberry Pi it may take days, but it’ll be interesting to see if it is feasible.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [May 18, 2018, 3:52pm UTC](https://discourse.slicer.org/t/how-to-build-3d-slicer-for-raspberry/2843/3 "2018-05-18T15:52:54Z")

</div>

Instead of compiling Slicer directly on the Raspberry, I suggest to look at using “cross-compilation” approaches.

In the past, we successfully cross-compiled ITK and VTK:

- [Kitware Blog: Cross-compile ITK’s Python Wrapping for the Raspberry Pi 2](https://blog.kitware.com/cross-compile-itks-python-wrapping-for-the-raspberry-pi-2/)
- [Kitware Blog: Raspberry Pi likes VTK](https://blog.kitware.com/raspberry-pi-likes-vtk/)

With the improvement to CMake (e.g support for cross-compiling emulator) as well as the work put into the dockcross project, it should be easier today.

- Cross compiling toolchains in Docker images : [https://github.com/dockcross/dockcross](https://github.com/dockcross/dockcross)
- [Kitware Blog: Cross-compiling for the Raspberry Pi, Evolved](https://blog.kitware.com/cross-compiling-for-the-raspberry-pi-evolved/)

Further experiments would be needed to compile Qt5. Here are some pointers:

- [https://wiki.qt.io/Native\_Build\_of\_Qt5\_on\_a\_Raspberry\_Pi](https://wiki.qt.io/Native_Build_of_Qt5_on_a_Raspberry_Pi)
- [https://visualgdb.com/tutorials/raspberry/qt/embedded/](https://visualgdb.com/tutorials/raspberry/qt/embedded/)

At first, I would also suggest to try to compile Slicer with the following options disabled:

```nohighlight
-DSlicer_USE_PYTHONQT:BOOL=OFF
-DSlicer_USE_PYTHONQT_WITH_TCL:BOOL=OFF
-DSlicer_BUILD_DICOM_SUPPORT:BOOL=OFF
-DSlicer_BUILD_DIFFUSION_SUPPORT:BOOL=OFF
-DSlicer_BUILD_EXTENSIONMANAGER_SUPPORT:BOOL=OFF
-DSlicer_BUILD_CLI:BOOL=OFF
-DBUILD_TESTING:BOOL=OFF
-DSlicer_BUILD_QTLOADABLEMODULES:BOOL=OFF
-DSlicer_BUILD_QTSCRIPTEDMODULES:BOOL=OFF

```

Also, since options like [CMAKE\_CROSSCOMPILING](https://cmake.org/cmake/help/v3.11/variable/CMAKE_CROSSCOMPILING.html) and [CMAKE\_CROSSCOMPILING\_EMULATOR](https://cmake.org/cmake/help/v3.11/variable/CMAKE_CROSSCOMPILING_EMULATOR.html) are not propagated down to external projects, I suggest to first build dependent libraries by starting with VTK, then ITK, …

To find in which order to build the dependency, you could look at the topological order displayed when configuring Slicer using a regular toolchain:

```bash
$ cmake ...
[...]
-- SuperBuild - First pass
-- SuperBuild - First pass - done
-- SuperBuild - Slicer => Requires curl, CTKAppLauncherLib, teem, VTKv9, ITKv4, CTK, LibArchive, RapidJSON, SimpleITK, SlicerExecutionModel, qRestAPI, DCMTK, python-pydicom, python-chardet, python-couchdb, python-GitPython, python-pip, python-PyGithub, CTKAPPLAUNCHER, python, NUMPY, incrTcl,
[...]

```

All project listed after **– SuperBuild - Slicer =\> Requires** are listed in topological order. (Note that in the case of building for Raspberry, less projects would be listed because of the disabled options.)

After all required projects are cross-compiled independently (e.g using dockcross), you could then configure Slicer also using dockcross with option like these ones:

```auto
cmake -DVTK_DIR:PATH= ... -DITK_DIR=PATH= ... -DSlicer_SUPERBUILD:BOOL=OFF ../Slicer

```

Also, since there are no prebuilt binaries of the launcher available for Raspberry, you could set `Slicer_USE_CTKAPPLAUNCHER` to `OFF` and use a shell script to set the startup environment.

Let us know if you have any questions,  
J-Christophe

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [May 20, 2018, 2:03pm UTC](https://discourse.slicer.org/t/how-to-build-3d-slicer-for-raspberry/2843/4 "2018-05-20T14:03:18Z")

</div>

I built Slicer on [Odroid-U2](http://www.hardkernel.com/main/products/prdt_info.php?g_code=G135341370451) out of technical interest on Arch Linux for ARM. There was just one more step to do :

build CTKAPPLAUNCHER,  
download [CTKAppLauncher pre-compiled for amd64](https://github.com/commontk/AppLauncher/releases/download/v0.1.21/CTKAppLauncher-0.1.21-linux-amd64.tar.gz),  
replace the x86\_64 blob by the locally compiled ARM binary,  
rename the package and patch the cmake file :

> ```
> diff --git a/SuperBuild/External_CTKAPPLAUNCHER.cmake b/SuperBuild/External_CTKAPPLAUNCHER.cmake
> index dda4e1a54..911cdb428 100644
> --- a/SuperBuild/External_CTKAPPLAUNCHER.cmake
> +++ b/SuperBuild/External_CTKAPPLAUNCHER.cmake
> @@ -30,7 +30,8 @@ if(Slicer_USE_CTKAPPLAUNCHER)
> set(CTKAPPLAUNCHER_ARCHITECTURE "i386")
> set(md5 "9fa2acb7d934a43720a0bee8679cbeff")
> elseif("${CTKAPPLAUNCHER_OS}" STREQUAL "linux")
> - set(md5 "57d9e6fc1fdfe42d78fc4e277b9559ba")
> + set(CTKAPPLAUNCHER_ARCHITECTURE "armv7l")
> + set(md5 "783455a7ee0bea086082f64da6adda1d")
> elseif("${CTKAPPLAUNCHER_OS}" STREQUAL "macosx")
> set(md5 "1f0d86b1eeb386d6892a76db7b111280")
> endif()
> 
> ```

Please not that if CTKAPPLAUNCHER\_ARCHITECTURE is not explicitely set, it defaults to i386. There’s probably a simpler way to build it automatically, I’m eager to learn about it.

It takes about 24 hours to build using all 4 cores with lowest nice priority. Here is a [video](https://mega.nz/#!lZ1lWDxS!txUyRsslaxzGvKWgKcBY9EGlQ_i2wWv0TmlO0Qacl8Y) captured with Slicer freshly started after rebooting the build device. (You may advance the video with the mouse, some simple steps are very long). Slices are never displayed in the viewers.

Of course it’s not for routine use. Just a curious thing to do in the background.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [May 30, 2018, 2:06pm UTC](https://discourse.slicer.org/t/how-to-build-3d-slicer-for-raspberry/2843/5 "2018-05-30T14:06:19Z")

</div>

Well done.

Out of curiosity, did you have to apply any other patch to Slicer/VTK/ITK/… or it “just worked” ?

> AppLauncher for ARM

If you could look at [dockcross](https://github.com/dockcross/dockcross#cross-compilers) identify the cross-compiler corresponding to Odroid-U2, it should be possible to have the corresponding launcher binaries automatically built and available AppLauncher [release](https://github.com/commontk/AppLauncher/releases) assets.

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [May 30, 2018, 3:15pm UTC](https://discourse.slicer.org/t/how-to-build-3d-slicer-for-raspberry/2843/6 "2018-05-30T15:15:55Z")

</div>

> [@jcfr](#):
>
> did you have to apply any other patch to Slicer/VTK/ITK/… or it “just worked” ?

I applied the patches mentioned [here](https://discourse.slicer.org/t/fyi-building-slicer-with-gcc-8-1/2830) because I used GCC 8.1 on the Odroid-U2 SoC too. I guess these three patches would not be needed for GCC \< 8, and it would just work.

Concerning cross-compiling, it’s certainly a good idea, I’ll dig into that when I find some time.

Concerning AppLauncher to be built locally, I understand that both with native or cross-compiling, the current cmake file does not build AppLauncher yet, it should be modified to download sources etc… and this is well beyond my skills.
