我试图使用Kilobot模拟器Kilombo和一个ROS包。我正在正常安装Kilombo,然后尝试在ROS包中包含Kilombo头文件。Kilombo的CMakeLists.txt如下所示
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)
我正在创建的ROS包的CMakeLists.txt如下所示:
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})
我将Kilombo头文件包括在内,与正常情况一样:
"#include <kilombo.h>"
但是,当我运行
catkin_make
时,会出现许多“未定义的引用”错误。其中一些信息是:orbit.c:53 undefined reference to 'kilo_turn_left'
orbit.c:53 undefined reference to 'set_motors'
这些消息显示在命令之后:
####
#### Running command: "make -j2 -l2" in "/home/viki/catkin_ws/build"
####
Linking C executable generated_test
kilo_turn_left
和函数set_motors
都是在“kilolib.h”中定义的,它本身也包含在“kilombo.h”中。如果尝试正常运行模拟,而不是作为ROS包运行,一切都可以正常工作。当我尝试运行Makefile时,它通常如下所示。我已经删除了为真实机器人而不是为模拟而编译的部分。
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
但是,当作为ROS包运行模拟时,我们需要定义一个CMakeLists.txt,这就是我遇到的问题。我到底做错了什么?
最佳答案
问题是我没有链接到模拟的CMakeLists.txt中的正确库。将线target_link_libraries(generated_test ${catkin_LIBRARIES})
更改为target_link_libraries(generated_test ${catkin_LIBRARIES} sim headless SDL m Jansson)
将其修复。