static compiled example exits with segfault

Dear members,
as I am quite new to ITK, I hope someone can help me out with this static runtime crash.
I am trying to statically compile an example from ITK to the statix ITK libraries.

make build dir
mkdir itk-static && cd itk-static


cmake --build . --parallel -j 8

Now I build a small example from the ITK examples:

mkdir /tmp/ReadAndPrintDICOMTags && cd /tmp/ReadAndPrintDICOMTags

Use the staic itk build in the previous step
cmake -DITK_DIR=/tmp/itk-static -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-static" /tmp/ITKExamples/src/IO/GDCM/ReadAndPrintDICOMTags/

The executable runs fine. I give it a path to a dicom series. However, on exit, it gives a segfault.

./ReadAndPrintDICOMTags /tmp/dicom/201


0040|2400 =
2050|0020 = IDENTITY
Patient’s Name (0010|0010) is: ex010
Segmentation fault

Tried ‘strace’ - all runs fine, until the last exit, does not return normally (exit 0 = SUCCESS) , but segfaults

munmap(0x7fca25fdd000, 167936) = 0
munmap(0x7fca24e3f000, 167936) = 0
munmap(0x7fca262e8000, 167936) = 0
munmap(0x7fca22c27000, 29032448) = 0
munmap(0x7fca28be3000, 135168) = 0
— SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=NULL} —
+++ killed by SIGSEGV +++
Segmentation fault

Does anyone see what I should do to make this work?

Thank you in advance,


Hello @Vincent,

Welcome to the ITK community! :sun_with_face:

This can cause issues. If a binary that just works across many linux platforms is desired, check out dockbuild.

Otherwise, -static is used with the executables generated, add -DITK_DYNAMIC_LOADING:BOOL=OFF to your ITK CMake configuration flags. But, dockbuild is preferred :-).


Thank you for your quick reply, Matt! I’ll give it a go and if it works, prolly should post some comment on this post:

1 Like

Thanks @matt.mccormick, worked like a charm. Added ref to the above post.

1 Like