c++ - CMakeList.txt 中应该包含什么模块来进行近似最近邻搜索?

标签 c++ cmake cmake-modules approximate-nn-searching

我编译了ANN-library并且需要在 C++ 文件中使用它来进行分割评估

我已经设置了 CMakeList.txt,它使用 ITK 和 ANN 库如下:

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})

但是,一旦我编译 C++ 文件,它就会引发错误:

/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

看来问题与链接库有关。我应该向 CMakeList.txt 添加任何特定行或模块吗?

最佳答案

这些方法在 ANN.lib 本身中定义,因此您不会错过添加任何库。在 find_library 调用中作为 PATH 参数传递的 ${ANN_PATH} 变量指向 header 包含文件夹。您应该使其指向包含该库的文件夹,并在继续进行 target_link_libraries 调用之前进行 if-check 以查看是否找到它。

关于c++ - CMakeList.txt 中应该包含什么模块来进行近似最近邻搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59271458/

相关文章:

c++ - CMake:使用静态库的共享库

cmake - 记录 CMake 模块的正确方法是什么?

qt - Cmake:访问qt虚拟键盘模块

linux - CMake 错误 "include could not find load file: FetchContent"

c++ - 构造函数是否必须在 C++ 中初始化成员变量?

cmake - 从 CMake 脚本构建 doxygen

cmake - 如何使用 CMake 的 ExternalProject_Add 重用提取的源代码?

c++ - 错误 : expression must have constant value. 对于一个明显的常量值

c++ - 二维白色网格不显示在背景上方

c++ - 为什么在 C++20 中使用 `std::bind_front` 而不是 lambda?