I have compiled ANN-library and need to use it in a C++ file for segmentation evaluation
I have set the CMakeList.txt, which is using ITK and ANN libraries as follows:
PROJECT(EvaluateSegmentationResult)
cmake_minimum_required(VERSION 3.14)
set(ANN_LIB /home/user/tools/ann_1.1.2/lib/)
set(ANN_PATH /home/user/tools/ann_1.1.2/include/)
#FIND_PACKAGE(ITK)
find_package(ITK COMPONENTS
ITKBinaryMathematicalMorphology
ITKCommon
ITKIOImageBase
ITKImageFunction
ITKImageGrid
ITKImageIntensity
ITKMathematicalMorphology
ITKThresholding
ITKImageIO
)
IF(ITK_FOUND)
INCLUDE(${ITK_USE_FILE})
ELSE(ITK_FOUND)
MESSAGE(FATAL_ERROR
"ITK not found. Please set ITK_DIR.")
ENDIF(ITK_FOUND)
FIND_PATH(ANN_PATH NAMES ANN)
FIND_LIBRARY(ANN_LIB NAMES ann PATHS ${ANN_PATH})
INCLUDE_DIRECTORIES(${ANN_PATH})
ADD_EXECUTABLE( EvaluateSegmentationResult EvaluateSegmentationResult.cpp)
#TARGET_LINK_LIBRARIES( EvaluateSegmentationResult ITKIO ITKBasicFilters ITKCommon ${ITK_LIBRARIES} ${ANN_LIB})
TARGET_LINK_LIBRARIES( EvaluateSegmentationResult ${ITK_LIBRARIES} ${ANN_LIB})
However, it raises an error once I am compiling the C++ file:
/home/user/tools/EvaluationSourceCode/EvaluateSegmentationResult.cpp:86: undefined reference to `annAllocPts(int, int)'
/home/user/tools/EvaluationSourceCode/EvaluateSegmentationResult.cpp:95: undefined reference to `ANNkd_tree::ANNkd_tree(double**, int, int, int, ANNsplitRule)'
/home/user/tools/EvaluationSourceCode/EvaluateSegmentationResult.cpp:135: undefined reference to `annAllocPts(int, int)'
/home/user/tools/EvaluationSourceCode/EvaluateSegmentationResult.cpp:144: undefined reference to `ANNkd_tree::ANNkd_tree(double**, int, int, int, ANNsplitRule)'
/home/user/tools/EvaluationSourceCode/EvaluateSegmentationResult.cpp:175: undefined reference to `annDeallocPts(double**&)'
/home/user/tools/EvaluationSourceCode/EvaluateSegmentationResult.cpp:176: undefined reference to `annDeallocPts(double**&)'
collect2: error: ld returned 1 exit status
CMakeFiles/EvaluateSegmentationResult.dir/build.make:128: recipe for target 'EvaluateSegmentationResult' failed
make[3]: *** [EvaluateSegmentationResult] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/EvaluateSegmentationResult.dir/all' failed
make[2]: *** [CMakeFiles/EvaluateSegmentationResult.dir/all] Error 2
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/EvaluateSegmentationResult.dir/rule' failed
make[1]: *** [CMakeFiles/EvaluateSegmentationResult.dir/rule] Error 2
Makefile:118: recipe for target 'EvaluateSegmentationResult' failed
make: *** [EvaluateSegmentationResult] Error 2
It seems the issue is related to link libraries. should I add any specific line or module to the CMakeList.txt
?
I could solve the issue by just adding
-lANN -LlibANN
to thetarget_link_libraries()
call: