Mac系统10.6,如果我有一个文件 “unwanted.c”,其中包含:如何真正在MacOS上
class secret_thing {
public:
secret_thing() {}
void revealing_method_name() {}
};
main()
{
secret_thing obj;
obj.revealing_method_name();
}
现在我做:
$ g++ unwanted.c -o unwanted
$ strip unwanted
$ nm unwanted | grep secret
0000000100000eb8 T __ZN12secret_thing21revealing_method_nameEv
0000000100000eae T __ZN12secret_thingC1Ev
如果我打出了接口和实现秘密类,正如大多数人在编写C++代码时所做的那样,在剥离的可执行文件中没有不需要的符号。不幸的是,我递交了一个有数千行代码的现有代码库,这不是我的选择之一。
我试过-fno-rtti,作为一个猜测,并没有解决任何问题。我曾向Google的众神祷告,并发现许多脱衣俱乐部的参考资料,但没有有用的链接。我已经浏览了mac上的strip,g ++和ld的手册页,并且没有明显的尝试,尽管“私人外部”这个短语很有趣,但我无法弄清楚该怎么做。
[更新] 不幸的是,我发现一个小例子的尝试是一个问题。这是一个更复杂的例子,它更接近真正的问题,如果它被优化,它仍然有不需要的符号。
对于不好的例子,我表示歉意。事实证明很难找到最小的实际问题。非常感谢答案,但每个答案都让我接近解决方案。
class base {
public:
virtual int revealing_method_name() = 0;
virtual ~base() {};
};
class secret_thing : public base {
public:
int revealing_method_name() { return 0; };
};
class other_thing : public base {
public:
int revealing_method_name() { return 1; };
};
int main(int argc, char**)
{
base *object = 0;
if(argc > 1) object = new secret_thing;
else object = new other_thing;
return object->revealing_method_name();
}
我发错了代码。带正确的示例代码,正如现在问题所读的问题,通过INSIDE类定义中的方法实现,strip表示: strip:无法在/ Users/michael中删除的间接符号表项引用的符号。玩具/不想要的 __ZN12secret_thing21revealing_method_nameEv __ZN12secret_thingC1Ev – mtoy 2009-12-19 02:04:51
但是,答案非常有用,因为它给了我更多谷歌饲料,错误字符串确实揭示了一些更有趣的调查领域。 – mtoy 2009-12-19 02:11:14