Ion*_*nic 6 c++ macos boost static-libraries
我在使用GCC 4.5的Mac OS X 10.6.6下遇到静态加速库(来自MacPorts的Boost 1.45.0-2,编译为fat/universal(x86/x86_64)库)的一些非常奇怪的问题.
错误消息是
main(78485) malloc: *** error for object 0x1000e0b20: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
[1] 78485 abort (core dumped)
Run Code Online (Sandbox Code Playgroud)
以及一小段示例代码将触发此问题:
#define BOOST_FILESYSTEM_VERSION 3
#include <boost/filesystem.hpp>
#include <iostream>
int main (int argc, char **argv) {
std::cout << boost::filesystem::current_path ().string () << '\n';
}
Run Code Online (Sandbox Code Playgroud)
将静态boost库链接到二进制文件时,总会出现此问题.但是,动态链接可以正常工作.
更多信息:
测试/使用的gcc版本: Apple GCC 4.2.1(工作/运行),MacPorts GCC 4.5.2(失败)
标记测试/使用:无,-fPIC,-fPIC -g,-fPIC -g -ggdb3 -gdwarf-2 -O0
MP GCC 4.5.2的gdb输出/上述任何标志:
(gdb) run
Starting program: /Users/ionic/crashtest/bin/ctest Reading symbols for shared libraries .++++++++++++++++++++++.................................................................................................................. done
ctest(80366) malloc: *** error for object 0x100fe6b20: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program received signal SIGABRT, Aborted. 0x00007fff81a4e616 in __kill ()
(gdb) bt full
#0 0x00007fff81a4e616 in __kill () No symbol table info available.
#1 0x00007fff81aeecca in abort () No symbol table info available.
#2 0x00007fff81a066f5 in free () No symbol table info available.
#3 0x0000000100f763e9 in std::string::_M_mutate () No symbol table info available.
#4 0x0000000100f7644c in std::string::_M_replace_safe () No symbol table info available.
#5 0x0000000100f77edd in std::string::replace () No symbol table info available.
#6 0x000000010000713d in std::string::_M_rep () at /usr/include/c++/4.2.1/bits/basic_string.h:1412
to = (string &) Cannot access memory at address 0x0
Run Code Online (Sandbox Code Playgroud)
似乎它与Apple的(相当古老的)GCC版本一起工作正常,但是MacPorts的新GCC构建失败了.
otool -L ctest:
./../../bin/ctest:
/opt/local/lib/gcc45/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.14.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0)
/opt/local/lib/gcc45/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
Run Code Online (Sandbox Code Playgroud)
我已经看到了与GCC 4.2和_GLIBCXX_DEBUG宏集相似的OS X错误的各种报告,但是这个看起来更通用,因为我既没有使用XCode,也没有设置宏(甚至取消定义它没有帮助.我试过它只是为了确保它与这个问题无关.)似乎与这个问题根本没有关系,因为相同的代码与Apple的GCC一起工作正常.
由于Apple的GCC还没有包含任何C++ 0x功能,我确实想使用当前稳定的GCC版本.
有没有人指出为什么会这样,甚至可能是一个解决方案(而不是使用动态库解决方法)?
最好的祝福,
米哈伊
问题是Boost是使用Apple的GCC 4.2.1构建的,而我一直在使用不同的编译器构建项目.
当我试图链接静态Boost库时,GCC 4.2.1 libstdc ++也被放入二进制文件中.然而,与此同时,另一个GCC版本在其libstdc ++中链接并且名称空间问题是固有的,因此调用了错误的函数等.
最简单的解决方法是使用目标GCC版本重新构建Boost,然后重新构建程序(使用自建的Boost.).
请注意:不要尝试更改MacPorts用于构建Boost的编译器(甚至不容易),否则可能会发生系统破坏.相反,您可以自己构建Boost.
| 归档时间: |
|
| 查看次数: |
3616 次 |
| 最近记录: |