How to find_package(another_package) in my workspace that my_package depends on

asked 2020-06-17 01:52:56 -0500

pfnusg@gmail.com gravatar image

updated 2020-06-17 04:54:01 -0500

Hi,

I have made a library package called serial and want to use it from another package in my workspace. Both the library package "serial" and the user package "pubtest" are in my workspace.

The serial library were built successfully, and installed via the CMakeList.txt

.........

include_directories(include)
ament_export_include_directories(include)
ament_target_dependencies(serial)

install(TARGETS ${PROJECT_NAME}
    DESTINATION lib/${PROJECT_NAME}
    PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}
)

Now from another package pubtest, i am calling into this the serial functions, but there is a linking problem to the function in serial, it seems like the library serial has not been included in the build; in CMakeList.txt;

find_package(serial REQUIRED)
set(dependencies "rclcpp" "std_msgs" "serial")
include_directories(include ${serial_INCLUDE_DIRS})
ament_target_dependencies(pubtest ${dependencies})

If i put add the line target_link_libraries(${PROJECT_NAME} serial)

The library serial is included, but the path is not correct.

Error log: LINK : fatal error LNK1181: cannot open input file 'serial.lib'

My question is why the library serial is not included in the build since i have set the ament_target_dependencies? And This looks like the environment path to where the serial library is located, how do i set the library path for other libraries/packages that exist the the same work space as the package that has its dependencies on?

edit retag flag offensive close merge delete

Comments

Please share more complete information since the problem might very well be in the lines you left out. E.g. for both packages the package.xml files as well as the CMakeLists.txt. Also knowing which ROS 2 distro you are using and on what platform might be helpful.

Dirk Thomas gravatar image Dirk Thomas  ( 2020-06-17 15:17:13 -0500 )edit