How to link `devel` directory for using library with pre-made custom library. [closed]

asked 2018-08-23 21:30:52 -0500

harderthan gravatar image

updated 2018-08-27 00:04:54 -0500

Hello, ROS experts. I referenced below two link.

On my project, there are two packages. For our convenience, I'll call these A and B project.

  • A project: This project have a general library, a pre-made library. (there are two library)
  • B project: This project will use two library from A project. --> There project placed on same catkin_workspace.

The problem is that I can't not use pre-made library on B project.

detail: I succeed it to install the pre-made library on catkin_ws/devel/lib. But, when I build the project B, It can not find pre-made library.

How can I fix this issue?

There is more detail on below description.


ProjectA, CMakeLists.txt

find_library(PreMade NAMES "caffe" PATHS "${PreMade_DIR}")  
message(STATUS "${PreMade}")  

find_package(catkin REQUIRED COMPONENTS  
  roscpp  
  roslib  
  std_msgs  
  interface_model  
)  

catkin_package(  
    CATKIN_DEPENDS roscpp std_msgs  
    LIBRARIES ${PROJECT_NAME}_lib PreMade  
    INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include ${PreMade_INCLUDEDIR}  
)  
...  

add_library(PreMade EXCLUDE_FROM_ALL ${PreMade} )  
add_custom_command(TARGET PreMade POST_BUILD COMMAND cp ${PreMade}  ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ )  
set_target_properties(PreMade PROPERTIES LINKER_LANGUAGE CXX )  
install( FILES ${PreMade}  
DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

ProjectA, CMakeLists.txt

 find_package(catkin REQUIRED COMPONENTS  
      roscpp  
      std_msgs  
      ProjectA  
    )  
    ...  
    add_executable(${PROJECT_NAME}_node ${SOURCES})  
    target_link_libraries(${PROJECT_NAME}_node  
        ${catkin_LIBRARIES}  
        ${OpenCV_LIBRARIES}  
        PreMade  
    )

Build Log(Catkin_make)

-- Configuring done  
-- Generating done  
-- Build files have been written to: /catkin_ws/build  
####  
#### Running command: "make -j8 -l8" in "/catkin_ws/build"  
####  
[  6%] Built target Caffe  
[ 26%] Built target interface_model_lib  
[ 40%] Built target refine_det_lib  
[ 93%] Linking CXX executable /catkin_ws/devel/lib/ProjectB/ProjectB_node  
/usr/bin/ld: cannot find -lProejctA_premade_lib  
collect2: error: ld returned 1 exit status  
ProjectB/CMakeFiles/ProjectB_node.dir/build.make:199: recipe for target  '/catkin_ws/devel/lib/ProjectB/ProjectB_node' failed  
make[2]: *** [/catkin_ws/devel/lib/ProjectB/ProjectB_node] Error 1  
CMakeFiles/Makefile2:1536: recipe for target 'ProjectB/CMakeFiles/ProjectB_node.dir/all' failed  
make[1]: *** [ProjectB/CMakeFiles/ProjectB_node.dir/all] Error 2  
Makefile:138: recipe for target 'all' failed  
make: *** [all] Error 2  
Invoking "make -j8 -l8" failed

  • In catkin_ws/devel/lib
    • [ProjectB]
    • libGeneralForProejctA.so
    • libPremade.so
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by harderthan
close date 2019-01-31 08:10:27.454495

Comments

Could you not use an imported target for the "premade library"? After setting the location property, export it like you do in the catkin_package(..) call. The cp step should not be needed.

gvdhoorn gravatar image gvdhoorn  ( 2018-08-24 02:52:21 -0500 )edit