How to use catkin_make with external C static library?

asked 2016-03-17 18:34:10 -0600

msaka gravatar image

Hello,

I am currently trying to use some external C functions in a ROS node. I have compiled the external C functions into a static .a library and am having problems linking it in my CMakeLists file. The static library is libmycfunc.a which I built previously based on my mycfunc.c and mycfunc.o files. When I compiled mycfunc.o the functions are dependent on additional static libraries lib1.a, lib2.a, and lib3.a. If I compile mycfunc.c with a main() as an executable, the external libraries lib1-3.a are linked properly I am able to use the executable.

As an example I am using the beginner_tutorials ROS package with the "talker" and "listener" nodes. I would like to use some of the functions in libmycfunc.a as a proof of concept however I am not very familiar with cmake. Below is my CMakeLists file:

cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  genmsg
)

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES beginner_tutorials
#  CATKIN_DEPENDS roscpp rospy std_msgs
#  DEPENDS system_lib
)

include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(talker src/talker.cpp)
add_dependencies(talker beginner_tutorials_generate_messages_cpp)
target_link_libraries(talker ${catkin_LIBRARIES}
                    <path_to_external_c_lib>/libmycfunc.a
)

add_executable(listener src/listener.cpp)
add_dependencies(listener beginner_tutorials_generate_messages_cpp)
target_link_libraries(listener ${catkin_LIBRARIES})

However when I catkin_make the beginner_tutorials package, I get errors:

Linking CXX executable /home/sakagma/catkin_ws/devel/lib/beginner_tutorials/talker
<path_to_c_func>/mycfunc.c: undefined reference to 'func1':

where "func1" is a function defined in the linked static library lib1.a used in mycfunc.c.

How do I properly link my static library libmycfunc.a so that I can call those functions in talker.cpp?

Note: In talker.cpp I am referencing my C functions by including:

extern "C" {
     #include "mycfunc.h"
}

Any help would be appreciated!

edit retag flag offensive close merge delete

Comments

1

Hi msaka, did you find a solution eventually ?

ankalou gravatar imageankalou ( 2016-04-19 08:52:49 -0600 )edit