Lib과 Share, include를 build안에 생성하고 시스템 안에 있는 library 특징 및 경로, 합치기 등을 해보기
18 Dec 2022 | Programming
특정 LIB에 생성이 안되는 문제
add_library를 이용하여서 특정 function에대한 라이브러리를 생성을 해야되고
install 함수를 이용하여서 해당 project 환경 library에 넣어줘야 한다.
보통 실행 파일은 bin에다 넣고, library 파일은 lib에다 넣는다.
install function중에 share folder에 해당 package folder 및 file들을 보존할 수 있다.
root library(system library)와 local library(user library), project library, ros library등 os에 여러 환경들이 존재한다.
하지만 공통적으로 존재한 폴더들이 있다.
- bin(실행파일)
- lib(library)
- include(library header 파일 및 개발 환경(기능)을 구성하는 header 파일)
- shared(library package folder)
- etc
이들은 즉 각 환경에서 가지고 있는 library들이 다르고 header 환경이 다르다. 그렇기 때문에 개발환경에 맞춰서 설치경로도 확인해야되고, 만약 library나 header를 못찾는다고 한다면, 현재 환경에 library가 깔려있는지, 다른 개발환경이면서 library가 깔려있는줄 착각하고 계속 불러오려고 하는지 확인을 해야된다.
만약 환경이 다른 곳에서 개발을 하고 있었으면, export 커맨드나 sh 파일을 실행하여서 환경변수를 맞춰주고 이를
env를 통해 확인한다.
만약 library들을 다 링킹해서 사용하고 싶다면,
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/hosting_users/test/module/okname
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/ros/noetic/lib/
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib
및 bashrc 파일에
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/hosting_users/test/module/okname
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/ros/noetic/lib/
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib
를 추가하고 source, 환경을 먹여주면 된다. 즉 글로벌하게 링킹을 걸어준다면 library 문제 없이 어디 어디서든 사용할 수 있다.
개발 노트
cmake_minimum_required(VERSION 3.0.2)
project(vision_obstacle_pkg)
Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
created by chan
set(LOG_SRC ${vision_obstacle_pkg_SOURCE_DIR}/include/vision_obstacle_pkg/log)
file(GLOB SRC_FILES ${LOG_SRC}/.h ${LOG_SRC}/.hpp ${LOG_SRC}/.cpp ${LOG_SRC}/.ipp)
if(MSVC OR MINGW)
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_unix.cpp)
else()
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_win.cpp)
endif(MSVC OR MINGW)
set(SRC_FILES ${SRC_FILES} ${SRC_PLATFORM_SPECIFIC})
create the g2log library
include_directories(${LOG_SRC})
MESSAGE(" g2logger files: [${SRC_FILES}]")
add_library(lib_g2logger ${LOG_SRC}/g2log.h ${LOG_SRC}/g2log.cpp ${LOG_SRC}/crashhandler_unix.cpp ${LOG_SRC}/crashhandler_win.cpp ${LOG_SRC}/crashhandler.h ${LOG_SRC}/g2future.h ${LOG_SRC}/g2logworker.h ${LOG_SRC}/g2moveoncopy.hpp ${LOG_SRC}/g2time.cpp ${LOG_SRC}/g2time.h ${LOG_SRC}/shared_queue.h )
add_library(lib_g2logger src/log/active.cpp src/log/crashhandler_unix.cpp src/log/crashhandler_win.cpp src/log/g2log.cpp src/log/g2logworker.cpp src/log/g2time.cpp)
add_library(plane_finder_module src/integral_image.cpp src/multi_plane_segmentation.cpp)
set_target_properties(lib_g2logger PROPERTIES LINKER_LANGUAGE CXX)
add_library(lib_g2logger_shared SHARED ${SRC_FILES})
add_library(lib_g2logger_shared SHARED ${SRC_FILES})
set_target_properties(lib_g2logger_shared PROPERTIES LINKER_LANGUAGE CXX)
created by chan done
created by chan`
find_package(nanoflann REQUIRED)
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
image_transport
nodelet
pluginlib
roscpp
rospy
sensor_msgs
tf2
tf2_geometry_msgs
tf2_ros
message_generation
pcl_ros
message_filters
grid_map_core
grid_map_msgs
grid_map_ros
)
find_package(Boost REQUIRED COMPONENTS system)
find_package(RapidJSON REQUIRED)
################################################
Declare ROS messages, services and actions
################################################
Generate messages in the 'msg' folder
add_message_files(
FILES
DrivableArea.msg
DrivableAreaList.msg
)
add_service_files(
FILES
SaveImage.srv
)
Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
geometry_msgs#
std_msgs
sensor_msgs# tf2_geometry_msgs
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES vision_obstacle_pkg
CATKIN_DEPENDS geometry_msgs image_transport nodelet pluginlib roscpp rospy sensor_msgs tf2 tf2_geometry_msgs tf2_ros pcl_ros message_runtime message_filters
DEPENDS system_lib
)
###########
Build
###########
include_directories(
include
lib
${catkin_INCLUDE_DIRS}
${RapidJSON_INCLUDE_DIRS}
INCLUDE_DIRECTORIES
vision_obstacle_pkg
LOG_SRC # created by chan.
)
src/normal_estimator.cpp src/ndt_estimator.cpp
add_library(plane_finder_module src/integral_image.cpp src/multi_plane_segmentation.cpp)
target_link_libraries(plane_finder_module ${catkin_LIBRARIES})
add_library(ransac_lib src/ndt_plane_estimator.cpp)
add_library(lib_g2logger src/log/active.cpp src/log/crashhandler_unix.cpp src/log/g2log.cpp src/log/g2logworker.cpp src/log/g2time.cpp
src/log/crashhandler_win.cpp
)
add_executable(test_module src/test.cpp)
target_link_libraries(test_module ${catkin_LIBRARIES} ${boost_LIBRARIES})
add_executable(image_saver_module src/image_saver.cpp)
target_link_libraries(image_saver_module ${catkin_LIBRARIES} ${boost_LIBRARIES})
add_library(multicam_ground_extractor_nodelet src/multicam_ground_extractor.cpp)
add_dependencies(multicam_ground_extractor_nodelet ${catkin_EXPORTED_TARGETS})
target_link_libraries(multicam_ground_extractor_nodelet plane_finder_module ransac_lib ${catkin_LIBRARIES})
add_library(multicam_obstacle_extractor src/obstacle_extractor.cpp)
target_link_libraries(multicam_obstacle_extractor PUBLIC plane_finder_module ransac_lib ${catkin_LIBRARIES}
lib_g2logger
nanoflann::nanoflann
)
add_executable(multicam_obstacle_extractor_node src/obstacle_extractor_node.cpp)
target_link_libraries(multicam_obstacle_extractor_node multicam_obstacle_extractor
lib_g2logger ${PLATFORM_LINK_LIBRIES} # created by chan
nanoflann::nanoflann # created by chan
)
add_executable(test_imu_pose src/imu_test.cpp)
target_link_libraries(test_imu_pose ${catkin_LIBRARIES} )
if (UNIX)
target_link_libraries(multicam_obstacle_extractor_node bsd)
endif(UNIX)
install(TARGETS plane_finder_module DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(TARGETS ransac_lib DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(TARGETS multicam_obstacle_extractor DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(TARGETS multicam_obstacle_extractor_node DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
install(TARGETS lib_g2logger DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(DIRECTORY launch/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
PATTERN ".svn" EXCLUDE)
install(DIRECTORY include/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/include
PATTERN ".svn" EXCLUDE)
install(DIRECTORY cfg/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cfg
PATTERN ".svn" EXCLUDE)
install(DIRECTORY scripts/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/scripts)
특정 LIB에 생성이 안되는 문제
add_library를 이용하여서 특정 function에대한 라이브러리를 생성을 해야되고
install 함수를 이용하여서 해당 project 환경 library에 넣어줘야 한다.
보통 실행 파일은 bin에다 넣고, library 파일은 lib에다 넣는다.
install function중에 share folder에 해당 package folder 및 file들을 보존할 수 있다.
root library(system library)와 local library(user library), project library, ros library등 os에 여러 환경들이 존재한다.
하지만 공통적으로 존재한 폴더들이 있다.
- bin(실행파일)
- lib(library)
- include(library header 파일 및 개발 환경(기능)을 구성하는 header 파일)
- shared(library package folder)
- etc
이들은 즉 각 환경에서 가지고 있는 library들이 다르고 header 환경이 다르다. 그렇기 때문에 개발환경에 맞춰서 설치경로도 확인해야되고, 만약 library나 header를 못찾는다고 한다면, 현재 환경에 library가 깔려있는지, 다른 개발환경이면서 library가 깔려있는줄 착각하고 계속 불러오려고 하는지 확인을 해야된다.
만약 환경이 다른 곳에서 개발을 하고 있었으면, export 커맨드나 sh 파일을 실행하여서 환경변수를 맞춰주고 이를
env를 통해 확인한다.
만약 library들을 다 링킹해서 사용하고 싶다면,
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/hosting_users/test/module/okname
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/ros/noetic/lib/
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib
및 bashrc 파일에
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/hosting_users/test/module/okname
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/ros/noetic/lib/
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib
를 추가하고 source, 환경을 먹여주면 된다. 즉 글로벌하게 링킹을 걸어준다면 library 문제 없이 어디 어디서든 사용할 수 있다.
개발 노트
cmake_minimum_required(VERSION 3.0.2)
project(vision_obstacle_pkg)
Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
created by chan
set(LOG_SRC ${vision_obstacle_pkg_SOURCE_DIR}/include/vision_obstacle_pkg/log)
file(GLOB SRC_FILES ${LOG_SRC}/.h ${LOG_SRC}/.hpp ${LOG_SRC}/.cpp ${LOG_SRC}/.ipp)
if(MSVC OR MINGW)
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_unix.cpp)
else()
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_win.cpp)
endif(MSVC OR MINGW)
set(SRC_FILES ${SRC_FILES} ${SRC_PLATFORM_SPECIFIC})
create the g2log library
include_directories(${LOG_SRC})
MESSAGE(" g2logger files: [${SRC_FILES}]")
add_library(lib_g2logger ${LOG_SRC}/g2log.h ${LOG_SRC}/g2log.cpp ${LOG_SRC}/crashhandler_unix.cpp ${LOG_SRC}/crashhandler_win.cpp ${LOG_SRC}/crashhandler.h ${LOG_SRC}/g2future.h ${LOG_SRC}/g2logworker.h ${LOG_SRC}/g2moveoncopy.hpp ${LOG_SRC}/g2time.cpp ${LOG_SRC}/g2time.h ${LOG_SRC}/shared_queue.h )
add_library(lib_g2logger src/log/active.cpp src/log/crashhandler_unix.cpp src/log/crashhandler_win.cpp src/log/g2log.cpp src/log/g2logworker.cpp src/log/g2time.cpp)
add_library(plane_finder_module src/integral_image.cpp src/multi_plane_segmentation.cpp)
set_target_properties(lib_g2logger PROPERTIES LINKER_LANGUAGE CXX)
add_library(lib_g2logger_shared SHARED ${SRC_FILES})
add_library(lib_g2logger_shared SHARED ${SRC_FILES})
set_target_properties(lib_g2logger_shared PROPERTIES LINKER_LANGUAGE CXX)
created by chan done
created by chan`
find_package(nanoflann REQUIRED)
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
image_transport
nodelet
pluginlib
roscpp
rospy
sensor_msgs
tf2
tf2_geometry_msgs
tf2_ros
message_generation
pcl_ros
message_filters
grid_map_core
grid_map_msgs
grid_map_ros
)
find_package(Boost REQUIRED COMPONENTS system)
find_package(RapidJSON REQUIRED)
################################################
Declare ROS messages, services and actions
################################################
Generate messages in the 'msg' folder
add_message_files(
FILES
DrivableArea.msg
DrivableAreaList.msg
)
add_service_files(
FILES
SaveImage.srv
)
Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
geometry_msgs#
std_msgs
sensor_msgs# tf2_geometry_msgs
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES vision_obstacle_pkg
CATKIN_DEPENDS geometry_msgs image_transport nodelet pluginlib roscpp rospy sensor_msgs tf2 tf2_geometry_msgs tf2_ros pcl_ros message_runtime message_filters
DEPENDS system_lib
)
###########
Build
###########
include_directories(
include
lib
${catkin_INCLUDE_DIRS}
${RapidJSON_INCLUDE_DIRS}
INCLUDE_DIRECTORIES
vision_obstacle_pkg
LOG_SRC # created by chan.
)
src/normal_estimator.cpp src/ndt_estimator.cpp
add_library(plane_finder_module src/integral_image.cpp src/multi_plane_segmentation.cpp)
target_link_libraries(plane_finder_module ${catkin_LIBRARIES})
add_library(ransac_lib src/ndt_plane_estimator.cpp)
add_library(lib_g2logger src/log/active.cpp src/log/crashhandler_unix.cpp src/log/g2log.cpp src/log/g2logworker.cpp src/log/g2time.cpp
src/log/crashhandler_win.cpp
)
add_executable(test_module src/test.cpp)
target_link_libraries(test_module ${catkin_LIBRARIES} ${boost_LIBRARIES})
add_executable(image_saver_module src/image_saver.cpp)
target_link_libraries(image_saver_module ${catkin_LIBRARIES} ${boost_LIBRARIES})
add_library(multicam_ground_extractor_nodelet src/multicam_ground_extractor.cpp)
add_dependencies(multicam_ground_extractor_nodelet ${catkin_EXPORTED_TARGETS})
target_link_libraries(multicam_ground_extractor_nodelet plane_finder_module ransac_lib ${catkin_LIBRARIES})
add_library(multicam_obstacle_extractor src/obstacle_extractor.cpp)
target_link_libraries(multicam_obstacle_extractor PUBLIC plane_finder_module ransac_lib ${catkin_LIBRARIES}
lib_g2logger
nanoflann::nanoflann
)
add_executable(multicam_obstacle_extractor_node src/obstacle_extractor_node.cpp)
target_link_libraries(multicam_obstacle_extractor_node multicam_obstacle_extractor
lib_g2logger ${PLATFORM_LINK_LIBRIES} # created by chan
nanoflann::nanoflann # created by chan
)
add_executable(test_imu_pose src/imu_test.cpp)
target_link_libraries(test_imu_pose ${catkin_LIBRARIES} )
if (UNIX)
target_link_libraries(multicam_obstacle_extractor_node bsd)
endif(UNIX)
install(TARGETS plane_finder_module DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(TARGETS ransac_lib DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(TARGETS multicam_obstacle_extractor DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(TARGETS multicam_obstacle_extractor_node DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
install(TARGETS lib_g2logger DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(DIRECTORY launch/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
PATTERN ".svn" EXCLUDE)
install(DIRECTORY include/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/include
PATTERN ".svn" EXCLUDE)
install(DIRECTORY cfg/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cfg
PATTERN ".svn" EXCLUDE)
install(DIRECTORY scripts/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/scripts)
Comments