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

Kris Thielemans kris.f.thielemans at gmail.com
Sat Dec 17 17:26:49 EST 2016


Thanks Matt

This works great. I like it better than using CMakeFindDependencyMacro's find_dependency that I stumbled on, as I believe that find_dependency could lead the user to link with a different ITK version, while your version forces usage of the same ITK version, which seems like a good thing to me!

So I'll be using 

if (@ITK_FOUND@)
  set(ITK_DIR "@ITK_DIR@")
  find_package(ITK REQUIRED)
endif()

as ITK is optional in my case.

By the way, this might be worth adding to the tutorial you mentioned (it's somewhat cryptic, but I'm getting there).

Thanks!
Kris

-----Original Message-----
From: Matt McCormick 
Sent: 17 December 2016 17:38
To: Kris Thielemans 
Cc: community at itk.org
Subject: Re: [ITK] link problems to library that uses ITK as external project

Hi Kris,

In the STIR CMake Config-file package [1], include code like:

  set(ITK_DIR "@ITK_DIR@")
  find_package(ITK REQUIRED)

where @ITK_DIR@ is set to the ITK Config-file location for the ITK used to build STIR using the CMake configure_file command. This will help client libraries or executables of STIR to find where ITK was located and load the location of ITK libraries like ITKCommon.

HTH,
Matt

[1] https://cmake.org/cmake/help/v3.7/manual/cmake-packages.7.html#id1

On Sat, Dec 17, 2016 at 10:14 AM, Kris Thielemans wrote:
> 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.
>
>
>
>
>
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>



More information about the Community mailing list