【ROS】在ROS内包含第三方库,并根据处理器架构自动调用
如图所示,在planning功能包内包含了第三方库armadillo,该库当前为x86_64架构下编译
在cmakelist中应做响应修改,使得cmake能识别该库
又由于不同系统架构下编译的库文件不通用,cmakelist应根据系统架构自行切换包含目录
cmakelist 修改如下
## 检测处理器架构体系
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i386")
message(STATUS "i386 architecture detected")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i686")
message(STATUS "i686 architecture detected")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
message(STATUS "x86_64 architecture detected")
set(LIBARMADILLO_LIB_DIR "${CMAKE_CURRENT_LIST_DIR}/3rd_party/amd_x86_64/armadillo_11.1.1/lib/libarmadillo.so") # matlab函数库armadillo
set(LIBARMADILLO_INC_DIR "${CMAKE_CURRENT_LIST_DIR}/3rd_party/amd_x86_64/armadillo_11.1.1/include ") # matlab函数库armadillo
else()
message(STATUS "host processor architecture is unknown")
endif()
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
${catkin_INCLUDE_DIRS}
include
${LIBARMADILLO_INC_DIR}
# ${ALL_INCS}
)
add_executable(${PROJECT_NAME}_node src/app/planning_node.cpp
${ALL_SRCS}
)
## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}_node
${catkin_LIBRARIES}
${LIBARMADILLO_LIB_DIR}
)
catkin_make编译时,终端中将打印当前处理器架构