【cmake】——find_path/find_library用法例子

例子

#在HINTS后的路径中找NvInfer.h, PATH_SUFFIXES:在每个搜索路径的子目录下搜索
find_path(TENSORRT_INCLUDE_DIR NvInfer.h
HINTS ${TENSORRT_ROOT} ${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES include)
find_library(TENSORRT_INFER libnvinfer.so
HINTS ${TENSORRT_ROOT} ${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES lib lib64 lib/x64)
find_library(TENSORRT_INFER_PLUGIN libnvinfer_plugin.so
HINTS ${TENSORRT_ROOT} ${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES lib lib64 lib/x64)

  • 后面使用的时候:
    target_link_libraries(trt ${TENSORRT_INFER} ${TENSORRT_INFER_PLUGIN})

  • 也可以在同时找多个.h / .so文件
    find_library(TENSORRT_INFER libnvinfer.so B.so C.so
    HINTS ${TENSORRT_ROOT} ${CUDA_TOOLKIT_ROOT_DIR}
    PATH_SUFFIXES lib lib64 lib/x64)

2. find_path 会用最后搜索到的结果
比如,我安装了两个eigen3,一个通过apt-get,安装在usr/include, 一个手动编译,在usr/local/include, 用find_path时返回usr/local/include路径

  find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
      PATHS
      include
      ${EIGEN_ADDITIONAL_SEARCH_PATHS}
      ${KDE4_INCLUDE_DIR}
      PATH_SUFFIXES eigen3 eigen
    )

这里的EIGEN3_INCLUDE_DIR=/usr/local/include

你可能感兴趣的:(c++,cmake,find_path,find_library)