# ITK on Julia, Shared Library Files

**URL:** https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117
**Category:** Community
**Created:** [August 2, 2019, 8:07pm UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117 "2019-08-02T20:07:39Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![cj-mclaughlin](https://discourse.itk.org/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@cj-mclaughlin](https://discourse.itk.org/u/cj-mclaughlin)
#### Post date: [August 2, 2019, 8:07pm UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117/1 "2019-08-02T20:07:39Z")

</div>

Hello, I was wondering if anyone had thought about/begun writing a Julia wrapper for ITK. My company has a C++ codebase but we are moving over to Julia, and I would like to be able to run our old code natively in Julia. For those of you who do not know, Julia supports calling C++ with a Cxx.jl package as long as it can have load the corresponding .so file. With CMake I was able to write a .so file but I was not able to load it due to issues with external variables. I would love to hear if anyone else is using ITK alongside Julia and if anyone has been able to fix this issue with loading .so files. Thanks.

---

<div class="post-metadata">

### Author: ![cj-mclaughlin](https://discourse.itk.org/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@cj-mclaughlin](https://discourse.itk.org/u/cj-mclaughlin)
#### Post date: [August 2, 2019, 10:09pm UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117/2 "2019-08-02T22:09:50Z")

</div>

I didn’t want to post any error details in the original post, as that seems a bit messy and bad practice for a community-driven forum.

I’m currently running into a LoadError from the Julia libdl wrapper when it tries to open my .so file:  
`LoadError: could not load library "/home/connor/ITKtest/libITK-shared.so" undefined symbol: _ZN3itk11LightObject6DeleteEv`

I compile my .so file with cmake via `add_library(ITK-shared SHARED ITKLib.cxx)`

I’ve poked around through similar ‘light-object’ related compilation errors, and it seems some people have issues with that due to external variables present, when they try to compile without a proper CMake file. However, my CMakeLists.txt file mirrors the format of that on the ITK Examples page, and my executable still compiles without any issues.

Does anyone have any suggestions as to how I would set up my shared libraries?

Thanks for putting up with the wall of text.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [August 5, 2019, 10:15am UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117/3 "2019-08-05T10:15:02Z")

</div>

Hello Connor,

I am not familiar with the details of Juilia plugins, but a good first approach is to build ITK with the `BUILD_SHARED_LIBS` CMake configuration variable `OFF`, and link ITK static libraries.

A second approach is to either manually load the ITK shared libraries, or make it possible for the plugin to find the location of the ITK libraries at runtime, which is a much more involved, platform-dependent process.

I hope this helps,  
Matt

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [August 5, 2019, 3:39pm UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117/4 "2019-08-05T15:39:09Z")

</div>

Hello,

I am not familiar with Julia’s ability to call C++, but I’d like to learn more. You may be interested in the SimpleITK interface to ITK. ITK itself is a toolkit which provides a templated C++ interface to its data objects and algorithms. SimpleITK provides a template free C++ interface to ITK’s images, filtering, and registration framework by instantiating ITK images and algorithms for numerous types. Here is the Image class’ Doxygen for an example: [https://itk.org/SimpleITKDoxygen/html/classitk\_1\_1simple\_1\_1Image.html](https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1Image.html)

However, the complication of loading the numerous ITK libraries will still be there. Although, with a little modification to SimpleITK, it all (including ITK) could be compiled into one library if needed.

It would be wonderful to add Julia support to the many languages already supported by SimpleITK. Please share any results or progress with us.

---

<div class="post-metadata">

### Author: ![cj-mclaughlin](https://discourse.itk.org/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@cj-mclaughlin](https://discourse.itk.org/u/cj-mclaughlin)
#### Post date: [August 5, 2019, 4:13pm UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117/5 "2019-08-05T16:13:57Z")

</div>

Thanks for your advice. Even after adjusting my CMake configuration and setting up static libraries, my shared library file seems to be unchanged (error message remained constant).

Do you have any examples of CMake configurations for similar purposes, or any suggestions as to how to go through the process of manually loading ITK libraries, as in your second approach?

Thanks,  
Connor

---

<div class="post-metadata">

### Author: ![cj-mclaughlin](https://discourse.itk.org/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@cj-mclaughlin](https://discourse.itk.org/u/cj-mclaughlin)
#### Post date: [August 5, 2019, 4:14pm UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117/6 "2019-08-05T16:14:42Z")

</div>

I’ll take a look into SimpleITK! Thank you for the idea, I’ll get back to you with any progress/potential issues.

---

<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: [August 5, 2019, 11:18pm UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117/7 "2019-08-05T23:18:51Z")

</div>

> [@cj-mclaughlin](#):
>
> \_ZN3itk11LightObject6DeleteEv

This is probably a mangled version of `itk::LightObject::Delete()`. Meaning that a definition of this method should be available, but it isn’t. I suggest you list all the symbols in `libITK-shared.so` to check whether the missing symbol is indeed missing. If it is, check whether something similarly named exists. Your Julia libdl wrapper might be compiled using a different version of C++ standard (e.g. C++11 vs C++03 vs C++14), and this might result in different mangling scheme, resulting in slightly different mangled name of most symbols, including `itk::LightObject::Delete()`.

---

<div class="post-metadata">

### Author: ![cj-mclaughlin](https://discourse.itk.org/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@cj-mclaughlin](https://discourse.itk.org/u/cj-mclaughlin)
#### Post date: [August 6, 2019, 1:42am UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117/8 "2019-08-06T01:42:47Z")

</div>

It turns out the issue was with what C++ standard I was using. I am now able to call ITK functions from Julia, so the real work can now begin. I’ll put together a couple basic functions and start up a repo. I’ll link it here in the next day or two so that you can keep up with any progress and give any feedback.

---

<div class="post-metadata">

### Author: ![cj-mclaughlin](https://discourse.itk.org/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@cj-mclaughlin](https://discourse.itk.org/u/cj-mclaughlin)
#### Post date: [August 7, 2019, 11:03pm UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117/9 "2019-08-07T23:03:56Z")

</div>

I’ve gotten an initial translation function done as a proof-of-concept, figured I would link the repo here so you all can follow it: [https://github.com/cj-mclaughlin/ITK.jl](https://github.com/cj-mclaughlin/ITK.jl)

My initial inclination is to write out objects and functions used in registration, hopefully breaking them into segments as laid out in [SimpleITK.](https://simpleitk.readthedocs.io/en/master/Documentation/docs/source/registrationOverview.html#id1)

If anyone has any feedback or advice on how to build this project out, I would be happy to keep in touch.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [August 9, 2019, 3:14am UTC](https://discourse.itk.org/t/itk-on-julia-shared-library-files/2117/10 "2019-08-09T03:14:15Z")

</div>

Cool, Connor – thanks for sharing! 👏
