[ITK] link problems to library that uses ITK as external project

Kris Thielemans kris.f.thielemans at gmail.com
Sat Dec 17 10:14:37 EST 2016


Hi all

 

I'm trying to add CMake export facilities to our open source library
http://github.com/UCL/STIR. This uses ITK for IO. I succeeded in modifying
my CMake files to "export" that when you link to my STIR-library, you also
needs to link to the ITK libraries. However, as I have installed ITK in a
non-standard location (I build STIR by setting ITK_DIR), so the ITK
libraries are not automatically found by the linker. I am now getting
linking errors in my final application (that uses STIR, and hence ITK). More
detail below. So, what am I missing in my CMake files to "export" the
location of the ITK libraries that were used when building STIR? 

 

I am using CMake 3.7.0 on CentOS 7 if that matters.

 

Thanks for your help

 

Kris Thielemans

 

Detail:

Our CMakeLists.txt files contain stuff like

 

find_package(ITK QUIET)

add_library(IO some_sources)

if (ITK_FOUND) 

  target_link_libraries(IO ${ITK_LIBRARIES})

endif()

 

This works nicely. Now I'm putting in the necessary stuff for an external
project to be able to link to our IO library. I'm following a scheme similar
to

https://rix0r.nl/blog/2015/08/13/cmake-guide/ (sorry, firefox claims that
this web-site uses an invalided certificate at the moment).

 

So I've added for instance

 

install(TARGETS IO EXPORT STIRTargets DESTINATION lib)

 

Checking the generated STIRTargets-release.cmake I see indeed that it
contains

 

set_target_properties(IO PROPERTIES

  IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"

  IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE
"ITKCommon;lots-of-others-itk-libraries"

)

 

So, now in my final STIR application that uses STIR, I have a simple
CMakeLists.txt with

 

find_package(STIR 3.0.0 REQUIRED)

include_directories(${STIR_INCLUDE_DIRS})

add_executable(testfile testfile.cxx )

target_link_libraries(testfile ${STIR_LIBRARIES})

 

However, when building this (on Lubuntu with gcc etc) I get lots of messages
like this

 

/usr/bin/ld: cannot find -lITKCommon

 

Indeed, in the generated link.txt I do not see anything that tells gcc/ld
where the ITK libraries would be.

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20161217/4d370868/attachment.html>


More information about the Community mailing list