4
votes

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?

2
We'd need a high quality crystal ball to answer this one. Try to reduce your problem to a small example (a ten-line program should be sufficient to demonstrate the issue) and then you can post it, complete with code and command line.Marc Glisse
If I could reduce my problem to a 10 line program with a single compilation command line then I'd be able to google every command line argument and find the problem myself. The shared library is LXDE's libfm, does that narrow it down a bit?Didi Kohen
Yes, once reduced, the problem would likely be obvious, that's kind of the point... First, you should only need to compile the file that provides the problematic widget, and this should still have the same issue. Then you can start removing large parts of that file. What is unlikely is that someone will guess what is failing while you are showing no code, no command line, etc.Marc Glisse

2 Answers

3
votes

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.

3
votes

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.