1

I build a C++ project of mine using clang++, using the following command line command (split into lines):

clang++
  -std=c++11
  -W -Wall -Wextra -pedantic -Wno-newline-eof -Werror
  -O4
  -I<dirs>
  -L<dirs>
  -l<libs>
  -framework <frameworks>
  -D <defs>
  -o <filename>
  <files>

However, when I run strings <filename>, several class names show up, despite the -O4 in the command line. I've tried -Wl,-s which should tell llvm to strip all symbols, but that doesn't remove these.

The class names that show up seem to all have one thing in common: they have a vtable. One of these classes is :

class MyClass {
public:
    virtual void myFunc() = 0;  
};

It shows up as the symbol :

N9namespace7MyClassE

I don't like it that my namespace and class names show up in the final file. How do I strip these? My binary is a command line utility, so only the main function should be exported.


Even after supplying -fno-rtti (as suggested by @n.m.), some names still remain, such as :

__ZN15MyClassInstance6myFuncEv

(MyClassInstance being a subclass of the MyClass above)

Additionally, even the names of global variables are in the binary.

4

1 回答 1

1

我通过提供 clang 参数解决了这个问题-fno-rtti,它禁用了 RTTI,这是我无论如何都不使用的 C++ 功能。

[编辑]
看起来-O4并不暗示strip,最后几个对我的类名的引用可以通过执行来删除strip

于 2013-01-28T11:27:50.960 回答