2

我正在尝试使用 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 中的这两行工作正常!

4

1 回答 1

5

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

target_link_libraries(${PROJECT_NAME} yaml-cpp)
于 2013-04-05T03:11:55.540 回答