链接库时对`boost::filesystem::path_traits::dispatch 的未定义引用?
undefined reference to `boost::filesystem::path_traits::dispatch when linking library?
我构建了 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*
我用strings
挖掘libboost_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
我构建了 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*
我用strings
挖掘libboost_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