- 与catkin_make不同,可以参考catkin build – Build Packages中文翻译版手册
- catkin build 默认会生成
.private
文件夹。链接时候可能出现失败的问题。catkin参数配置之软连接模式
改为如下模式即可
catkin init
catkin config --merge-devel
catkin build
Bug
Issue1: 引用工作空间下别的包的lib报错
参考CmakeLists.txt import and export官方文档
假设ov_core需要被ov_msckf调用,一般情况ov_core需要export他自身。
- ov_core的CmakeLists
//自定义一个super_point_glue_lib
add_library(super_point_glue_lib SHARED
src/track/super_point.cpp
src/track/super_glue.cpp
)
target_link_libraries(super_point_glue_lib
nvinfer
nvonnxparser
${OpenCV_LIBRARIES}
${CUDA_LIBRARIES}
yaml-cpp
tensorrtbuffer_ov_core
)
//自定义ov_core_lib
list(APPEND LIBRARY_SOURCES
src/dummy.cpp
src/cpi/CpiV1.cpp
src/cpi/CpiV2.cpp
src/sim/BsplineSE3.cpp
src/track/TrackBase.cpp
src/track/TrackAruco.cpp
src/track/TrackDescriptor.cpp
src/track/TrackKLT.cpp
src/track/TrackSIM.cpp
src/types/Landmark.cpp
src/feat/Feature.cpp
src/feat/FeatureDatabase.cpp
src/feat/FeatureInitializer.cpp
src/utils/print.cpp
)
file(GLOB_RECURSE LIBRARY_HEADERS "src/*.h")
add_library(ov_core_lib SHARED ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
#target_link_libraries(ov_core_lib ${thirdparty_libraries} )
target_link_libraries(ov_core_lib super_point_glue_lib ${thirdparty_libraries} ) # add super_point_glue_lib
target_include_directories(ov_core_lib PUBLIC src/)
install(TARGETS ov_core_lib
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
install(DIRECTORY src/
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp"
)
- ov_msckf
find_package(catkin QUIET COMPONENTS roscpp rosbag tf std_msgs geometry_msgs sensor_msgs nav_msgs visualization_msgs image_transport cv_bridge ov_core ov_init message_generation)
catkin_package(
CATKIN_DEPENDS roscpp rosbag tf std_msgs geometry_msgs sensor_msgs nav_msgs visualization_msgs image_transport cv_bridge ov_core ov_init seg_ros message_runtime
INCLUDE_DIRS src/
LIBRARIES ov_msckf_lib
)
list(APPEND thirdparty_libraries
${Boost_LIBRARIES}
${OpenCV_LIBRARIES}
${CERES_LIBRARIES}
${catkin_LIBRARIES}
)
list(APPEND LIBRARY_SOURCES
src/dummy.cpp
src/sim/Simulator.cpp
src/state/State.cpp
src/state/StateHelper.cpp
src/state/Propagator.cpp
src/core/VioManager.cpp
src/core/VioManagerHelper.cpp
src/update/UpdaterHelper.cpp
src/update/UpdaterMSCKF.cpp
src/update/UpdaterSLAM.cpp
src/update/UpdaterZeroVelocity.cpp
)
file(GLOB_RECURSE LIBRARY_HEADERS "src/*.h")
add_library(ov_msckf_lib SHARED ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
target_link_libraries(ov_msckf_lib yaml-cpp ${thirdparty_libraries})
这里提供一个补救小技巧,当前面没有进行正常的install操作,但是ov_msckf
包依旧想链接super_point_glue_lib
时,可以手动指定这个包的位置。一般情况下,如果像ov_core
那样正常export和install,那么ov_msckf
就可以找到。
# wzy import this lib
# add_library(super_point_glue_lib SHARED IMPORTED)
# set_property(TARGET super_point_glue_lib PROPERTY
# IMPORTED_LOCATION "/home/zph/vins_ws/devel/lib/libsuper_point_glue_lib.so")
# target_link_libraries(ov_msckf_lib super_point_glue_lib yaml-cpp ${thirdparty_libraries}) # wzy change