Didi Kohen
Didi Kohen

Reputation: 560

Symbols stay local and not exported properly

A colleague gave me a modified version of a shared library where he added a GTK widget.
When inspecting the shared library file I see that the new widget functions are defined as local and not global.
I have tried to set the visibility attribute of GCC on the function (after the declaration itself, before the semicolon), it has G_BEGIN_DECLS around it and the same common headers and defines as other files in the library that are exported properly.
Is there a linker command line option I may be missing? A list of files that "can" export that is used by gcc, perhaps another definition for exported functions?

Upvotes: 5

Views: 1516

Answers (2)

Didi Kohen
Didi Kohen

Reputation: 560

I've found out that the library uses a regular expression to filter exports (the -export-symbols-regex switch), adding another regular expression made the symbols properly exported, now I everything is linking properly.

Upvotes: 3

Employed Russian
Employed Russian

Reputation: 213375

When inspecting the shared library file I see that the new widget functions are defined as local and not global.

By default, all symbols in a shared library are exported (unless you compile with -fvisibility=hidden or protected.

Since observe that your symbols are LOCAL, it is a good bet that your link command uses a linker version script to control symbol visibility (to hide all symbols except ones that are explicitly exported), and that you have not modified that version script to add your functions to the export list.

Look for -Wl,--version-script=... on your link command line, and modify the version script appropriately.

See also this answer.

Upvotes: 4

Related Questions