ITK on Julia, Shared Library Files

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.

2 Likes

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.

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

1 Like

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

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.

1 Like

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

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

1 Like

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().

1 Like

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.

2 Likes

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

My initial inclination is to write out objects and functions used in registration, hopefully breaking them into segments as laid out in SimpleITK.

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

3 Likes

Cool, Connor – thanks for sharing! :clap: