1

我正在使用 mingw-w64 (4.8.0) + cmake 为 yaml-cpp (0.5.1) 构建共享库。该项目在其附带的 CMakeLists.txt 中有一些构建目标:主库yaml-cpp和一些测试程序,例如parse,链接库。

库目标yaml-cpp本身构建时没有错误,但在parse构建时会出现此错误:

Linking CXX executable parse.exe
CMakeFiles\parse.dir/objects.a(parse.cpp.obj):parse.cpp:(.text+0x1a3): undefined reference to `YAML::Load(std::istream&)'
CMakeFiles\parse.dir/objects.a(parse.cpp.obj):parse.cpp:(.text+0x1b2): undefined reference to `YAML::operator<<(std::ostream&, YAML::Node const&)'
c:/work/mingw64-4.8/bin/../lib/gcc/x86_64-w64-mingw32/4.8.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\parse.dir/objects.a(parse.cpp.obj): bad reloc address 0x0 in section `.data'
collect2.exe: error: ld returned 1 exit status
util\CMakeFiles\parse.dir\build.make:90: recipe for target 'util/parse.exe' failed
mingw32-make[3]: *** [util/parse.exe] Error 1
CMakeFiles\Makefile2:228: recipe for target 'util/CMakeFiles/parse.dir/all' failed
mingw32-make[2]: *** [util/CMakeFiles/parse.dir/all] Error 2
CMakeFiles\Makefile2:240: recipe for target 'util/CMakeFiles/parse.dir/rule' failed
mingw32-make[1]: *** [util/CMakeFiles/parse.dir/rule] Error 2
makefile:211: recipe for target 'parse' failed
mingw32-make: *** [parse] Error 2

当我尝试使用该库编写小型测试程序时遇到类似的错误,我不知道出了什么问题。这里可能是什么问题?

4

1 回答 1

1

Jesse Beder 的评论指出了导致问题中描述的错误的确切问题。在后续版本中修复此问题的快速修复是将补丁 ( https://code.google.com/p/yaml-cpp/issues/detail?id=216#c4 ) 应用于yaml-cpp 0.5.1。std::string node_data::empty_scalar在源文件中还有一行声明src/node_data.cpp应该被注释掉。进行这些更改后,共享库和实用程序将毫无错误地构建。

于 2013-08-24T01:33:14.350 回答