c++ conflicting versions when loading package

好久不见. 提交于 2019-12-12 05:20:12

问题


I know nothing from c++. I installed two versions of some package called ITK. For some reason, the 4.8 version has its .cmake file in /usr/local/lib/cmake/ITK-4.8/UseITK.cmake and the 3.16 file /usr/local/itk/lib/InsightToolkit/UseITK.cmake.

So now, I am trying to build some project that requires 3.16 version that has in its CMakeLists.txt this :

find_package(ITK)
...
include( ${ITK_USE_FILE} )

but ${ITK_USE_FILE} is /usr/local/lib/cmake/ITK-4.8/UseITK.cmake. (what I understand is that ITK uses ITK_USE_FILE as Package_INCLUDE_DIR variable). How can I make find_package points to the 3.16 version ?


回答1:


Check that file /usr/local/itk/lib/InsightToolkit/ITKConfig.cmake exists and set ITK_DIR variable to /usr/local/itk/lib/InsightToolkit before finding package:

# CMakeLists.txt
...
set(ITK_DIR /usr/local/itk/lib/InsightToolkit)
find_package(ITK)

or, if you want your project to work also on other computers, pass this variable to cmake call:

cmake -DITK_DIR=/usr/local/itk/lib/InsightToolkit (...)

(CMakeLists.txt remains unchanged in that case).


According to the sources, FindITK.cmake (triggered with find_package(ITK) command) just redirect request to Config mode:

# FindITK.cmake
...
find_package(ITK ${_ITK_REQUIRED} ${_ITK_QUIET} NO_MODULE
    NAMES ITK InsightToolkit
    CONFIGS ITKConfig.cmake
    )

but does not pipe VERSION parameter to it. That's why setting version doesn't work.

Setting ITK_DIR forces CMake to search ITKConfig.cmake firstly under given directory. More details can be found in find_package documentation.




回答2:


Following the CMake documentation, you can request a specific version of the package to be found. You will need to change the CMakeLists.txt from:

find_package(ITK)

to:

find_package(ITK 3.16)


来源:https://stackoverflow.com/questions/32386349/c-conflicting-versions-when-loading-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!