c++ - 未定义的引用链接 yaml-cpp 程序与 mingw-w64 + cmake

标签 c++ cmake mingw yaml-cpp

我正在使用 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

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

最佳答案

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

关于c++ - 未定义的引用链接 yaml-cpp 程序与 mingw-w64 + cmake,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18390694/

相关文章:

c++ - cin.get() 空行问题

c++ - C++ header 差异

c - Windows 中 CMake 的默认生成器是什么?

c++ - 尝试使用对 protobuffers 2.6.1 和 3.4.1 的引用来编译代码

windows - 如何使用依赖于 libiconv 的 MinGW 安装 go 包

c++ - GLUT程序链接错误

c++ - 应该使用 std::stof 和 atof 之间的区别是什么?

c++ - 指针 : p++ & p+1

c++ - 在 Visual Studio 中将 OpenMP 与 Clang 和 CMake 结合使用

c++ - 如何在 Eclipse C++ 中使用 -std-c++11