Question: I'm building a C++ executable. I'm statically linking several of the C and C++ libraries I'm using, including a custom one. (I am not, however, statically linking every library I'm using.)

Even taking that into account, the executable seemed abnormally large. I used `objdump -h`, which told me that I was using far more space in `.dynstr` than I expected. I've compiled with `-Os` and run `strip`, but when I run

```
$ readelf -p .dynstr slamshift

```

I get many entries like

```
  [ 13588]  _ZN3yuu6windowC2Ev
  [ 1359b]  _ZTSN3yuu7gfx_ctxE
  [ 135ae]  _ZN4YAML7Scanner11ScanFlowEndEv
  [ 135ce]  __glewVertexFormatNV

```

for symbols in the libraries I've statically linked (my own library, yaml-cpp, and GLEW).

Why are these symbols appearing in my executable? If I've statically linked the libraries involved, shouldn't the symbol names be unnecessary?

I am using Ubuntu 12.04, GCC 4.6.3, and CMake and its default settings to build, if those are relevant.

Answer: 
> 
> Why are these symbols appearing in my executable?
> 
> 
> 

There are only two reasons for these symbols to be exported from your executable and appear in the dynamic symbol table.

1. You linked your executable with `--export-dynamic` (aka `-E`) linker flag, or
2. Some other shared library participating in the link references these symbols.

If you are doing #1, the answer is simple: don't do it.

If you got the symbols exported because of #2, you really want the symbols to be exported, otherwise the code will likely fail elsewhere.
It is a little-known fact that ELF executables can be opened as dynamic objects using dl\_open and friends. For that to work they need to have symbol exports. I think that is what is happening here.

You could try doing the final program link using `--exclude-libs ALL` to the linker. It would look like `-Wl,--exclude-libs ALL` on the gcc command line.  

*Update: this results in symbols still existing, but marked as Hidden.*

You might also try `-Wl,--exclude-all-symbols`.  

*Update: I was wrong about this one. It is for PE targets only.*

I tried this and it worked:  

`gcc -static -Wl,-s export-test.c`