在我的项目中,我想将xbee external library与ROS一起使用。
最初当我制作exe文件时我使用makefile。但由于ROS使用catkin,我必须使用Cmakelists.txt
创建exe文件
但我仍然坚持同样的错误undefined reference ..
,即使我遵循了所有方向。
My Project的目录结构如下所示。
.
├── xbee_ansic_library
├── include - 3 subdirectories have h file
├── wpan
├── xbee
└── zigbee
├── src - subdirectories have c file
├── wpan
├── xbee
└── zigbee
└── my_project
├── src
└── main.cpp
└── CMakeLists.txt
由于原始的makefile看起来像this,我写了my_project / CmakeLists.txt,如下所示。
project(my_project)
## Declare a catkin package
catkin_package()
# %EndTag(FULLTEXT)%
include_directories(include ${catkin_INCLUDE_DIRS})
include_directories(~/catkin_ws/src/xbee_ansic_library/include)
include_directories(~/catkin_ws/src/my_project/include)
LINK_DIRECTORIES(~/catkin_ws/src/xbee_ansic_library/src)
LINK_DIRECTORIES(~/catkin_ws/src/my_project/src)
add_library(base_OBJECTS
${xbee_ansic_library_SRC_POSIX}/xbee_platform_posix.c
${xbee_ansic_library_SRC_POSIX}/xbee_serial_posix.c
${xbee_ansic_library_SRC_UTIL}/hexstrtobyte.c
${xbee_ansic_library_SRC_UTIL}/memcheck.c
${xbee_ansic_library_SRC_UTIL}/swapbytes.c
${xbee_ansic_library_SRC_UTIL}/swapcpy.c
${xbee_ansic_library_SRC_UTIL}/hexdump.c src/parse_serial_args.c)
add_library(xbee_OBJECTS
${base_OBJECTS}
${xbee_ansic_library_SRC_WPAN}/wpan_types.c
${xbee_ansic_library_SRC_XBEE}/xbee_device.c
${xbee_ansic_library_SRC_XBEE}/xbee_atcmd.c)
....
add_executable(main src/main.cpp)
target_link_libraries(main ${catkin_LIBRARIES} main_OBJECTS)
add_dependencies(main my_project_generate_messages_cpp)
但是当我用catkin_make
命令时,我收到了错误
CMakeFiles / main.dir / src / main.cpp.o:在函数
main': main.cpp:(.text+0x177): undefined reference to
中xbee_dev_dump_settings' collect2:错误:ld返回1退出状态
但是xbee_dev_dump_settings
位于xbee_ansic_library/include/xbee/device.h
,xbee_ansic_library/src/xbee/xbee_device.c
。
由于错误undefined reference ..
没有,not declared ..
我觉得我在标题方面做得很好。
接下来应该做什么?
答案 0 :(得分:0)
错误发生在链接阶段,因此可能与您的target_link_libraries
行有关。我相信它还应该指定您创建的xbee和基本库,因此将其更改为:
target_link_libraries(main ${catkin_LIBRARIES} base_OBJECTS xbee_OBJECTS)