在ROS中使用yaml-cpp出错



我正在尝试使用yaml-cpp,根据wiki,这是一个系统依赖,所以我们甚至不需要更改CMakelists.txt或manifest.xml。然而,当我编译代码时,我仍然得到如下错误:

/home/aramus/fuerte_workspace/sandbox/image_test/src/image_test.cpp:53: undefined reference to `YAML::Parser::Parser(std::basic_istream<char, std::char_traits<char> >&)'
/home/aramus/fuerte_workspace/sandbox/image_test/src/image_test.cpp:54: undefined reference to `YAML::Node::Node()'
/home/aramus/fuerte_workspace/sandbox/image_test/src/image_test.cpp:92: undefined reference to `YAML::Node::~Node()'
/home/aramus/fuerte_workspace/sandbox/image_test/src/image_test.cpp:92: undefined reference to `YAML::Parser::~Parser()'
/home/aramus/fuerte_workspace/sandbox/image_test/src/image_test.cpp:92: undefined reference to `YAML::Node::~Node()'
/home/aramus/fuerte_workspace/sandbox/image_test/src/image_test.cpp:92: undefined reference to `YAML::Parser::~Parser()'
/home/aramus/fuerte_workspace/sandbox/image_test/src/image_test.cpp:92: undefined reference to `YAML::Node::~Node()'
/home/aramus/fuerte_workspace/sandbox/image_test/src/image_test.cpp:92: undefined reference to `YAML::Parser::~Parser()'

我添加到CMakeLists.txt的唯一代码是:

target_link_libraries(${PROJECT_NAME} yaml-cpp)
rosbuild_add_executable(image_test src/image_test.cpp)

我在Linux中使用fuerte。有解决方案吗?

编辑:我找到解决办法了!我改变了我的CMakeLists.txt先构建可执行文件,然后添加yaml-cpp库!

rosbuild_add_executable(image_test src/image_test.cpp)
target_link_libraries(image_test yaml-cpp)

这两行在我的CMakeLists.txt工作很好!

这些都是链接错误。确保链接到库并包含其头文件。从您提供的链接来看,在您的CMakeLists.txt文件中,您需要:

target_link_libraries(${PROJECT_NAME} yaml-cpp)

最新更新