问题
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