cyrusbehr / YOLOv8-TensorRT-CPP

YOLOv8 TensorRT C++ Implementation
MIT License
568 stars 70 forks source link

Make this project as a shared library #68

Closed alanc2000 closed 2 weeks ago

alanc2000 commented 2 weeks ago

Hi, thanks for the great work. I'm able to run the detection. However, i want make this project as a library to be shared with other packages in my workspace. I have been trying to modify the cmakelist.txt but i couldn't link the TensorRT and yolov8 library. The error that i encountered is:

/usr/bin/ld: CMakeFiles/2D_3DFrustum_ros2cpp.dir/src/2D_3DFrustum_ros2cpp.cpp.o: warning: relocation against _ZTV6Logger' in read-only section.text._ZN6LoggerD2Ev[_ZN6LoggerD5Ev]' /usr/bin/ld: CMakeFiles/2D_3DFrustum_ros2cpp.dir/src/2D_3DFrustum_ros2cpp.cpp.o: in function Logger::~Logger()': 2D_3DFrustum_ros2cpp.cpp:(.text._ZN6LoggerD2Ev[_ZN6LoggerD5Ev]+0x13): undefined reference tovtable for Logger' /usr/bin/ld: /root/rover_ws/install/yolo_tensor_cpp/lib/libYoloV8_TRT.so: undefined reference to `Int8EntropyCalibrator2::Int8EntropyCalibrator2(int, int, int, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::array<float, 3ul> const&, std::array<float, 3ul> const&, bool, bool)' /usr/bin/ld: warning: creating DT_TEXTREL in a PIE

This is my cmakelist.txt: cmake_minimum_required(VERSION 3.8) project(2D_3DFrustum)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif()

set(CUDA_TOOLKIT_ROOT_DIR /usr/local/cuda)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

set(TensorRT_DIR /usr/lib/python3.10/dist-packages/tensorrt/)

find_package(ament_cmake REQUIRED) find_package(OpenCV REQUIRED) find_package(rclcpp REQUIRED) find_package(rclcpp_components REQUIRED) find_package(sensor_msgs REQUIRED) find_package(cv_bridge REQUIRED) find_package(yolo_tensor_cpp REQUIRED) find_package(tensorrt_cpp_api REQUIRED) find_package(CUDA REQUIRED) find_package(OpenCV REQUIRED) find_package(TensorRT REQUIRED)

find_library(YOLOV8_TRT_LIBRARY NAMES YoloV8_TRT PATHS /root/rover_ws/install/yolo_tensor_cpp/lib)

add_executable(2D_3DFrustum_ros2cpp src/2D_3DFrustum_ros2cpp.cpp) target_include_directories(2D_3DFrustum_ros2cpp PUBLIC ${OpenCV_INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS} ${TensorRT_INCLUDE_DIRS})

target_link_libraries(2D_3DFrustum_ros2cpp ${OpenCV_LIBS} ${CUDA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${TensorRT_LIBRARIES} ${YOLOV8_TRT_LIBRARY})

target_compile_features(2D_3DFrustum_ros2cpp PUBLIC c_std_99 cxx_std_17)

install(TARGETS 2D_3DFrustum_ros2cpp DESTINATION lib/${PROJECT_NAME})

ament_target_dependencies(2D_3DFrustum_ros2cpp OpenCV rclcpp rclcpp_components sensor_msgs cv_bridge yolo_tensor_cpp tensorrt_cpp_api)

if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) set(ament_cmake_copyright_FOUND TRUE) set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif()

ament_package()

I am just a ros2 beginner. Sorry if my code looks messy. Hopefully can get help from you all. Thank you!

alanc2000 commented 2 weeks ago

solved. I shared included and exported libraries - YoloV8_TRT and tensorrt_cpp_api. Now able to share the package. Thanks.