问题描述
在我们的iPhone XCode 3.2.1项目中,我们链接了两个外部静态C ++库libBlue.a和libGreen.a。 libBlue.a全局覆盖了 运算符,用于自己的内存管理。然而,当我们构建我们的项目时,libGreen.a使用libBlue的 new 运算符,这导致崩溃(可能是因为libBlue.a正在做出关于分配的结构的种类的假设)。 libBlue.a和libGreen.a是由第三方提供的,所以我们不能改变他们的任何源代码或构建选项。
当我们删除libBlue.a从项目,libGreen.a没有任何问题。然而,没有数量的改组的图书馆的链接顺序似乎解决了问题,也没有任何实验与各种连接标志。有没有办法告诉XCode告诉链接器让libGreen使用 new 运算符使用标准的C ++ new 运算符而不是libBlue重新定义的运算符? / p>
也许你可以使用,沿着 objcopy --redefine-sym oldNew = newNew libBlue.a
的行。我看到的最大的问题是,苹果的开发工具套件似乎不包括objcopy。您可以从( sudo port install binutils
)安装objcopy, ),但是objcopy可能无法处理ARM对象文件。 MacPorts中有几个ARM binutils,我猜猜 arm-elf-binutils
是你最好的选择。
除此之外,你可以反汇编libBlue.a,用
sed
脚本重命名它的新操作符,然后重新组装它。也许你甚至可以直接操作libBlue.a符号表。 In our iPhone XCode 3.2.1 project, we're linking in 2 external static C++ libraries, libBlue.a and libGreen.a. libBlue.a globally overrides the "new" operator for it's own memory management. However, when we build our project, libGreen.a winds up using libBlue's new operator, which results in a crash (presumably because libBlue.a is making assumptions about the kinds of structures being allocated). Both libBlue.a and libGreen.a are provided by 3rd parties, so we can't change any of their source code or build options.
When we remove libBlue.a from the project, libGreen.a doesn't have any issues. However, no amount of shuffling the linking order of the libraries seems to fix the problem, nor does any experimentation with the various linking flags. Is there some way to tell XCode to tell the linker to "have libGreen's use of the new operator use the standard C++ new operator rather than the one redefined by libBlue"?
Perhaps you could investigate using GNU objcopy, something along the lines of objcopy --redefine-sym oldNew=newNew libBlue.a
. The biggest problem I see with this is that Apple's developer tool suite doesn't seem to include objcopy. You can install objcopy from MacPorts (sudo port install binutils
), but that objcopy probably can't manipulate ARM object files. There are a couple of ARM binutils in MacPorts, and I'm guessing arm-elf-binutils
is your best bet.
Barring that, you could possibly disassemble libBlue.a, rename its new operator with a sed
script, then reassemble it. Perhaps you could even manipulate the libBlue.a symbol table directly.
这篇关于如何防止全局覆盖的“新”操作符从外部库链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!