且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在CMake中链接外部HDFql库

更新时间:2022-06-14 23:29:03

问题是我需要包含库 /usr/local/hdfql-2.1.0/wrapper/cpp/libHDFql.so 使用 /usr/local/hdfql-2.1.0/lib/libHDFql.so 。这非常令人发疯,因为参考手册没有对此进行提及,我花了太长时间才弄清楚这一点。哦,我希望这对其他人有帮助。

The problem was that I needed to include the library /usr/local/hdfql-2.1.0/wrapper/cpp/libHDFql.so, where I was using /usr/local/hdfql-2.1.0/lib/libHDFql.so. It's pretty maddening, since the reference manual doesn't make any mention of this and I spent way too long figuring this out. Ohwell, I hope this helps anyone else with this problem.

作为参考,下面是一个最小的柔cat风格的CMakeList,可以使用:

For reference, here is a minimal catkin-style CMakeLists that will work:

cmake_minimum_required(VERSION 3.2)
project(project_name)

add_compile_options(-std=c++11)

find_package(catkin_simple REQUIRED)
catkin_simple(ALL_DEPS_REQUIRED)

set(HDFQL_ROOT "path/to/hdfql-2.1.0")

include_directories(${HDFQL_ROOT}/include)

set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "-std=c++11 -pthread ${CMAKE_CXX_FLAGS}")

cs_add_executable(
    ${PROJECT_NAME}
    # your source file 1
    # your source file 2 
    # ...
)

target_include_directories(${PROJECT_NAME}
    PUBLIC "${HDFQL_ROOT}/include"
)

target_link_libraries(
   ${PROJECT_NAME}
   ${OpenCV_LIBRARIES}
)

target_link_libraries(
   ${PROJECT_NAME}
   "${HDFQL_ROOT}/wrapper/cpp/libHDFql.so"
)

当然,绝对路径不是很漂亮,替代方法是将 /usr/local/hdfql-2.1.0/lib 添加到环境变量 CMAKE_PREFIX_PATH (例如 export CMAKE_PREFIX_PATH = / usr / local / hdfql-2.1.0 / lib:$ CMAKE_PREFIX_PATH )。

Of course the absolute paths aren't very pretty, the alternative is to add /usr/local/hdfql-2.1.0/lib to the environment variable CMAKE_PREFIX_PATH (eg export CMAKE_PREFIX_PATH="/usr/local/hdfql-2.1.0/lib:$CMAKE_PREFIX_PATH").