Mac OS X和静态加速库 - >标准::字符串失败 [英] Mac OS X and static boost libs -> std::string fail

查看:140
本文介绍了Mac OS X和静态加速库 - >标准::字符串失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了静态Boost库一些很奇怪的问题(升压从MacPorts的1.45.0-2,编译成脂肪/通用(86 / x86_64的)库)在Mac OS X 10.6.6使用GCC 4.5。

I'm experiencing some very weird problems with static boost libraries (Boost 1.45.0-2 from MacPorts, compiled as fat/universal (x86/x86_64) libraries) under Mac OS X 10.6.6 with GCC 4.5.

该错误消息

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)

和例如code的一点​​点,这将触发此问题:

and a tiny bit of example code which will trigger this problem:

#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';
}

此问题链接静态Boost库为二进制的时候总是发生。动态链接将正常工作,虽然。

This problem always occurs when linking the static boost libraries into the binary. Linking dynamically will work fine, though.

更多的信息:

版本的GCC测试/使用的:苹果GCC 4.2.1(作品/运行),GCC MacPorts的4.5.2(失败)

gcc versions tested/used: Apple GCC 4.2.1 (works/runs), MacPorts GCC 4.5.2 (fails)

标志测试/使用的:无,-fPIC,-fPIC -g,-fPIC -g -ggdb3 -gdwarf-2 -O0

flags tested/used: none, -fPIC, -fPIC -g, -fPIC -g -ggdb3 -gdwarf-2 -O0

与MP GCC GDB输出4.5.2 /上述的任何标志:

(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

好像它的正常工作与苹果公司(很旧)版本的GCC,但随着新的GCC没有被严重的MacPorts建设。

Seems like it's working fine with Apple's (quite old) GCC version, but failing badly with the new GCC build by MacPorts.

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)

我已经看到了使用GCC 4.2和_GLIBCXX_DEBUG宏观组颇为相似的OS X漏洞的各种报告,但是这一次似乎更通用的,因为我既不用X code,也没有设置宏(甚至取消定义它并不能帮助。我想这只是为了确保它真的没有涉及这个问题。)似乎没有在所有的这个问题,是相关一样code做工精致与苹果的GCC。

I've seen various reports for quite a similar OS X bug with GCC 4.2 and the _GLIBCXX_DEBUG macro set, but this one seems even more generic, as I'm neither using XCode, nor setting the macro (even undefining it does not help. I tried it just to make sure it's really not related to this problem.) Doesn't seem to be related at all to this problem, as the same code is working fine with Apple's GCC.

由于苹果的GCC不包括任何的C ++ 0x还拥有,我确实喜欢使用当前稳定版本的GCC

As Apple's GCC doesn't include any C++0x features yet, I'd indeed like to use the currently stable GCC version.

没有任何人有任何指针,为什么发生这种情况,甚至可能的解决方案(而不是使用动态库解决方法)?

Does anybody have any pointers to why this is happening or even maybe a solution (rather than using the dynamic library workaround)?

最好的问候,

米哈伊

推荐答案

但问题是,升压使用苹果的GCC 4.2.1已经建成,而我一直在使用不同的编译器生成项目。

The problem was that Boost has been built using Apple's GCC 4.2.1, whilst I've been building the project using a different compiler.

当我试图链接的静态Boost库,同时也是GCC 4.2.1的libstdc ++投入二进制文件。
然而,在同一时间其他版本的GCC在其++的libstdc和名称空间问题进行了链接固有的,因此错误的函数的调用等等。

As I tried to link the static Boost libraries, also the GCC 4.2.1 libstdc++ was put into the binary. However, at the same time the other GCC version was linking in its libstdc++ and name space problems were inherent, thus the wrong functions were called and the like.

最简单的解决方法是重新建设加速与您的目标GCC版本(使用自建升压OFC。)重试你的程序的建设

The most simple fix is re-building Boost with your target GCC version and retry the building of your program (ofc. using the self-built Boost.)

被警告:不要试图改变编译器使用MacPorts的建设加速(它甚至不容易可能),否则可能发生系统损坏。相反,自己建的推动作用。

Be warned: do not try to change the compiler MacPorts uses for building Boost (it's even not easily possible), or system breakage may occur. Instead, build Boost on your own.

这篇关于Mac OS X和静态加速库 - &GT;标准::字符串失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆