Linking external headers file in ROS package
I am trying to use the Kilobot simulator Kilombo with a ROS package. I am installing Kilombo as normal as a system library. I am then trying to include the Kilombo header file inside the ROS package to create a Kilombo simulation. The CMakeLists.txt of Kilombo looks like this:
add_library(sim display.c skilobot.c kbapi.c params.c stateio.c runsim.c neighbors.c distribution.c gfx/SDL_framerate.c gfx/SDL_gfxPrimitives.c gfx/SDL_gfxBlitFunc.c gfx/SDL_rotozoom.c)
add_library(headless skilobot.c kbapi.c params.c stateio.c runsim.c neighbors.c distribution.c)
set_target_properties(headless PROPERTIES COMPILE_DEFINITIONS "SKILO_HEADLESS")
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-std=c99)
add_definitions("-Wall -O2 -g")
# add_definitions("-Wall -O3 -march=native -g")
endif()
INSTALL(TARGETS sim headless
ARCHIVE DESTINATION lib
)
INSTALL(FILES kilombo.h DESTINATION include)
INSTALL(FILES kilolib.h message.h message_crc.h params.h skilobot.h
DESTINATION include/kilombo)
add_subdirectory(tests)
The CMakeLists.txt of the ROS package I am creating looks like this:
cmake_minimum_required(VERSION 2.8.3)
project(Kilombo_test)
find_package(catkin REQUIRED roscpp std_msgs)
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-std=c99)
add_definitions("-Wall -O2 -g")
endif()
include_directories(/usr/local/include /usr/local/lib)
link_directories(/usr/local/include)
add_executable(generated_test orbit.c)
target_link_libraries(generated_test ${catkin_LIBRARIES})
I include the Kilombo header files just as normal: #include <kilombo.h>
However, when I run catkin_make, I get many "undefined reference" errors. Some of those messages are:
orbit.c:53 undefined reference to 'kilo_turn_left'
orbit.c:53 undefined reference to 'set_motors'
These messages are shown after the commands:
####
#### Running command: "make -j2 -l2" in "/home/viki/catkin_ws/build"
####
Linking C executable generated_test
Both, kilo_turn_left
and the function set_motors
is defined in "kilolib.h" which itself is included in "kilombo.h".
Everything works fine if try running the simulation normally and not as a ROS package. The Makefile when I try to run it normally looks like the following. I have removed the parts which compiled for the real bot and not for the simulation.
SOURCES=orbit.c
EXECUTABLE=orbit
# path of kilombo.h distributed with the simulator but also needed
# when compiling the user program for the real kilobot (avr-gcc has different default paths)
SIMHEADERS=/usr/local/include
#path to kilolib.a in the official kilolib, needed for real bots only
KILOLIB =$(KILOHEADERS)/build/kilolib.a
SIM_CFLAGS = -c -g -O2 -Wall -std=c99
SIM_LFLAGS = -lsim -lSDL -lm -ljansson
sim: $(EXECUTABLE)
hex: $(EXECUTABLE).hex
all: sim hex
clean :
rm *.o $(EXECUTABLE) *.elf *.hex
However, when running a simulation as a ROS package, we need to define a CMakeLists.txt which is what I am having trouble with. What exactly am I doing wrong? I know there are many similar questions on this board but I have not been able to find a solution to my problem in those questions (though I believe I have gotten closer to the solution)