Correct Way to Include DCMTK in CMakeLists.txt

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
samee
Posts: 17
Joined: Thu, 2023-03-30, 15:27

Correct Way to Include DCMTK in CMakeLists.txt

#1 Post by samee »

I am getting a linking error like the following while trying to add DCMTK to my project.

Code: Select all

[100%] Linking CXX executable dicom_reader
/usr/bin/ld: cannot find -lofstd
/usr/bin/ld: cannot find -loflog
/usr/bin/ld: cannot find -ldcmdata
/usr/bin/ld: cannot find -li2d
/usr/bin/ld: cannot find -ldcmimgle
...
I found that there is another recent post https://forum.dcmtk.org/viewtopic.php?f=1&t=5249 with the same issue. I tried to follow the solution but unfortunately could not get it to work.

Here is what I am doing to build DCMTK and install it in a local directory.

Code: Select all



wget https://github.com/DCMTK/dcmtk/archive/refs/tags/DCMTK-3.6.7.zip
unzip DCMTK-3.6.7.zip
cd dcmtk-DCMTK-3.6.7/
mkdir build_man
cd build_man/
cmake -DCMAKE_INSTALL_PREFIX=/home/samee/local_install/   -DCMAKE_PREFIX_PATH=/home/samee/local_install/  -DDCMTK_WITH_ICONV=OFF -DBUILD_SHARED_LIBS=ON  ..
make install
Here is my CMakeLists.txt file. And I use the following cmake command : cmake -DCMAKE_PREFIX_PATH=/home/samee/local_install//usr/local/ ..

Code: Select all

cmake_minimum_required(VERSION 3.20)
project(DicomReader)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCE main.cpp)
add_executable(dicom_reader ${SOURCE})
find_package(DCMTK REQUIRED CONFIG)
include_directories(${DCMTK_INCLUDE_DIRS})
link_directories("/home/samee/local_install/usr/local/lib")
target_link_libraries(dicom_reader PRIVATE ${DCMTK_LIBRARIES})

find_package(ZLIB REQUIRED)
target_link_libraries(dicom_reader PRIVATE ${ZLIB_LIBRARIES} )



samee
Posts: 17
Joined: Thu, 2023-03-30, 15:27

Re: Correct Way to Include DCMTK in CMakeLists.txt

#2 Post by samee »

Few updates. I reordered the link_directories() and add_executable() calls and the linking error is gone. However, now I get the following error:

Code: Select all

./dicom_reader: error while loading shared libraries: liboflog.so.17: cannot open shared object file: No such file or directory
using ldd shows the the following output

Code: Select all

samee@desk:/mnt/hdd8/axle/dev/dcmtk_reader/build$ ldd dicom_reader 
        linux-vdso.so.1 (0x00007ffe1cdd9000)
        libofstd.so.17 => /mnt/hdd8/axle/dev/dcmtk_reader/build/dcmtk_install/usr/local/lib/libofstd.so.17 (0x00007fdd2065d000)
        libdcmdata.so.17 => /mnt/hdd8/axle/dev/dcmtk_reader/build/dcmtk_install/usr/local/lib/libdcmdata.so.17 (0x00007fdd2046d000)
        libdcmjpeg.so.17 => /mnt/hdd8/axle/dev/dcmtk_reader/build/dcmtk_install/usr/local/lib/libdcmjpeg.so.17 (0x00007fdd20425000)
        libdcmjpls.so.17 => /mnt/hdd8/axle/dev/dcmtk_reader/build/dcmtk_install/usr/local/lib/libdcmjpls.so.17 (0x00007fdd20405000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fdd20215000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fdd201f5000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdd2001d000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fdd1fff5000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fdd1fead000)
        liboflog.so.17 => not found
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fdd1fe8d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fdd206b5000)
        libijg8.so.17 => not found
        libijg12.so.17 => not found
        libijg16.so.17 => not found
        libdcmimgle.so.17 => not found
        liboflog.so.17 => not found
        libdcmtkcharls.so.17 => not found
        libdcmimgle.so.17 => not found
        liboflog.so.17 => not found
So, it means it finds some libraries while fails to find the other. I can modify the LD_LIBRARY_PATH and get it working. But somehow that seems unnatural. Can anyone help me to point out what I need to fix?
Thanks.

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Correct Way to Include DCMTK in CMakeLists.txt

#3 Post by Michael Onken »

This is the natural way to do it. Or copy the .so files to a path that is already searched, like /usr/local/lib, or, copy them to the directory where the dicom_reader binary resides. The latter works on windows, at least, but I think also on Linux.

BR, Michael

samee
Posts: 17
Joined: Thu, 2023-03-30, 15:27

Re: Correct Way to Include DCMTK in CMakeLists.txt

#4 Post by samee »

Thanks for the reply.

I did few more google search and what I understand is this behavior is due to the difference between how direct and indirect dependencies are resolved (at least in Linux). Here is a link that discusses this:
https://stackoverflow.com/questions/520 ... d#52020177

I added the following line to my CMakeLists.txt and that seems to resolve the issue. Although, I still need to understand it's implications in my package distribution workflow.

Code: Select all

target_link_libraries(dicom_reader "-Wl,--disable-new-dtags")
-Samee

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest