我正在尝试将Kilobot模拟器Kilombo与ROS包一起使用。我正常安装Kilombo,然后尝试将Kilombo头文件包含在ROS包中。 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”中定义,“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,这是我遇到的问题。我究竟做错了什么?
答案 0 :(得分:0)
问题在于我没有链接到模拟的CMakeLists.txt中的正确库。将行target_link_libraries(generated_test ${catkin_LIBRARIES})
更改为target_link_libraries(generated_test ${catkin_LIBRARIES} sim headless SDL m Jansson)
修正了它。