Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding exporting symbols from executables on Linux

I'm finding that when I link an executable against a static library (.a), the symbols from the static library end up being exported by the executable file. I would like to avoid this and export nothing.

I've tried providing a version script, but it seems to make no difference. The contents of my version script are as follows:

{
    global:
        main;
    local:
        *;
};

Is there a way to not export symbols from an executable when linking in a static library? I can't recompile the static library itself.

like image 404
Ray Avatar asked Mar 03 '10 21:03

Ray


2 Answers

Executables don't export symbols by default, and will not do so unless you use -Wl,--export-dynamic. This is necessary only if you're dynamically loading libraries that themselves need to link into symbols in the main executable (this is a common case in C++ if your libraries contain classes which override virtual methods in the exe)

Perhaps you're confusing exporting symbols with having debug symbols. Debug symbols will be produced for the benefit of the debugger (if you don't strip the exe), but are not required to run.

like image 137
MarkR Avatar answered Oct 02 '22 19:10

MarkR


Use strip ?

$ man strip

like image 32
Paul R Avatar answered Oct 02 '22 19:10

Paul R