c++ - 链接库时未定义对 `boost::filesystem::path_traits::dispatch 的引用?

标签 c++ boost

我构建Gource项目。执行 make 时出现编译错误.

g++ -std=gnu++0x -Wall -Wno-sign-compare -Wno-reorder -Wno-unused-but-set-variable -Wno-unused-variable -g -O2 -pthread -pthread -o gource src/gource-action.o src/gource-bloom.o src/gource-caption.o src/core/gource-conffile.o src/core/gource-display.o src/core/gource-frustum.o src/core/gource-fxfont.o src/core/gource-logger.o src/core/gource-mousecursor.o src/core/gource-plane.o src/core/gource-ppm.o src/core/gource-quadtree.o src/core/gource-regex.o src/core/gource-resource.o src/core/gource-sdlapp.o src/core/gource-seeklog.o src/core/gource-settings.o src/core/gource-shader.o src/core/gource-shader_common.o src/core/gource-stringhash.o src/core/gource-texture.o src/core/gource-png_writer.o src/core/gource-timezone.o src/core/gource-vbo.o src/core/gource-vectors.o src/gource-dirnode.o src/gource-file.o src/formats/gource-apache.o src/formats/gource-bzr.o src/formats/gource-commitlog.o src/formats/gource-custom.o src/formats/gource-cvs-exp.o src/formats/gource-cvs2cl.o src/formats/gource-git.o src/formats/gource-gitraw.o src/formats/gource-hg.o src/formats/gource-svn.o src/gource-gource.o src/gource-gource_shell.o src/gource-gource_settings.o src/gource-key.o src/gource-logmill.o src/gource-main.o src/gource-pawn.o src/gource-slider.o src/gource-spline.o src/gource-textbox.o src/gource-user.o src/gource-zoomcamera.o src/tinyxml/gource-tinyxmlerror.o src/tinyxml/gource-tinystr.o src/tinyxml/gource-tinyxml.o src/tinyxml/gource-tinyxmlparser.o -lGL -lGLU -lfreetype -lpcre -lGLEW -lGLU -lGL -lSDL2_image -lSDL2 -lpng15 -lboost_system -lboost_filesystem src/gource-gource_settings.o: In function boost::filesystem::path::path<boost::filesystem::directory_entry>(boost::filesystem::directory_entry const&, boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<boost::filesystem::directory_entry>::type>, void>::type*)': /usr/include/boost/filesystem/path.hpp:139: undefined reference to boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator >&, std::codecvt<wchar_t, char, __mbstate_t> const&)' collect2: error: ld returned 1 exit status

使用libboost_filesystem.so.1.53.0构建环境。

⋊> /h/m/Gource on master ◦  ll /usr/lib64/libboost_filesystem.so                                                                                                                                                                                        18:26:31
lrwxrwxrwx. 1 root root 29 Sep 27  2020 /usr/lib64/libboost_filesystem.so -> libboost_filesystem.so.1.53.0*

我使用stringslibboost_filesystem.so.1.53.0并找到类似 boost::filesystem::path_traits::dispatch 的符号.

⋊> /h/m/Gource on master ◦  strings /usr/lib64/libboost_filesystem-mt.so | grep path_traits                                                                                                                                                             18:29:50
_ZN5boost10filesystem11path_traits8dispatchERKNS0_15directory_entryERSsRKSt7codecvtIwc11__mbstate_tE
_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEERKSt7codecvtIwc11__mbstate_tE
_ZN5boost10filesystem11path_traits7convertEPKwS3_RSsRKSt7codecvtIwc11__mbstate_tE

查找符号:

> ⋊> /h/m/Gource on master ◦ nm -DC /usr/lib64/libboost_filesystem.so | grep dispatch
0000000000007800 T boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::string&, std::codecvt<wchar_t, char, __mbstate_t> const&)

库显示如下:

⋊> /h/m/Gource on master ◦  ls /usr/lib64/libboost_filesystem.so* -l                                                                                                                                                                                    19:22:03
lrwxrwxrwx. 1 root root     29 Sep 27  2020 /usr/lib64/libboost_filesystem.so -> libboost_filesystem.so.1.53.0*
-rwxr-xr-x. 1 root root  94760 Apr  1  2020 /usr/lib64/libboost_filesystem.so.1.53.0*
-rwxr-xr-x. 1 root root 103592 Apr 24  2019 /usr/lib64/libboost_filesystem.so.1.69.0*

这个编译错误是什么意思?提前致谢。

最佳答案

您的图书馆有这个符号:

boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::string&, std::codecvt<wchar_t, char, __mbstate_t> const&)

但是你的链接器正在寻找这个:

boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator >&, std::codecvt<wchar_t, char, __mbstate_t> const&)

区别在于 .so 文件中的 std::string 又名 std::basic_string ,但应用程序中的 std::__cxx11::basic_string 。

当 C++11 标准化时,GCC 必须更改其 std::string 实现。他们在 GCC 5 中做到了这一点。我想您有 GCC 5 或更高版本。您可以通过使用 -D _GLIBCXX_USE_CXX11_ABI=0 编译来告诉 GCC 使用旧的 ABI,这样它将与您已安装的库兼容。或者您可以安装使用 GCC 5 或更高版本构建的新 Boost 库。也许您安装的Boost 1.69.0库使用了新的ABI,您可以尝试nm来找出答案。

参见:Understanding GCC 5's _GLIBCXX_USE_CXX11_ABI or the new ABI

关于c++ - 链接库时未定义对 `boost::filesystem::path_traits::dispatch 的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67399782/

相关文章:

c++ - 需要一些建议来选择合适的容器

c++ - 无法使用 cygwin 运行 cmake

c++ - 检查完整类型

c++ - 为什么使用 boost 会大大增加文件大小?

c++ - 处理 boost 变量和 boost 函数

c++ - std::make_pair 与 c++ 11

c++ - 如何从成员函数中释放对象?

c++ - 为什么 MCARDS 中需要前突变

c++ - 如何在线程完成时使用 boost::thread::at_thread_exit 或调用函数

c++ - 编译器如何决定是否值得让我的函数内联?