为什么STL代码似乎静态链接到Darwin上的Boost动态库?
当我使用gcc 4.6.1和toolset = darwin在OS X上构建Boost 1.42 / 1.46.1 / 1.49时,我发现生成的库静态地包含了很多STL代码,例如std :: basic_string< char>和std :: basic_string< wchar_t>。
在OS X 10.6.8的基础上,我得到以下结果:
% otool -L /usr/local/boost-1.46.1/lib/libboost_system.dylib
boost-1.46.1/lib/libboost_system.dylib:
libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
/usr/local/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
基于'otool -L'
输出,很明显libstdc ++没有与库动态链接。相比之下,在Ubuntu 12.04 LTS上,libboost_system.so 1.46.1显示了以下链接:
% ldd /usr/local/lib/libboost_system.so
linux-vdso.so.1 => (0x00007fff495ff000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fec4edb4000)
libstdc++.so.6 => /usr/local/lib64/libstdc++.so.6 (0x00007fec4ea82000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fec4e788000)
libgcc_s.so.1 => /usr/local/lib64/libgcc_s.so.1 (0x00007fec4e573000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fec4e355000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fec4df98000)
/lib64/ld-linux-x86-64.so.2 (0x00007fec4f1e4000)
在这种情况下,libstdc ++显然是动态链接的。在OS X方面,我就知道STL代码已直接包含在Boost库中:
% nm -gfj /usr/local/boost-1.46.1/lib/libboost_system.dylib | c++filt --format=gnu-v3 | egrep "^std::basic_string"
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_disjunct(char const*) const
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_last_of(char const*, unsigned long) const
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_last_of(char const*, unsigned long, unsigned long) const
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_last_of(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long) const
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_last_of(char, unsigned long) const
... [180 more lines] ...
答案 0 :(得分:2)
只是选择一个例子:
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_last_of(char const*, unsigned long) const
std :: basic_string是一个模板类,在libstdc ++。dylib中不存在。它是在编译boost库时实例化的,并且(正确地)包含在那里 - 因为Boost.System使用它。
我怀疑(但不知道)对于你看到的所有电话都是如此。