I have a problem linking some shared library with g++. It gives me a warning like:
hidden symbol XXX in YYY is referenced by DSO /usr/lib/...
I've read some related questions about particular problems, but I want to understand it in a whole - what does this warning mean and what is a cause:
- What is DSO?
- What is a hidden symbol?
- How can it be referenced, if it's hidden?
What is a DSO?
A DSO is a Dynamic Shared Object, or less formally a shared library.
What is a hidden symbol?
A hidden symbol is a symbol (i.e. name of function or data object) that has been compiled with hidden linkage, e.g. as per the (GCC specific) declaration:
If
x
is defined in one DSO then dynamic linkage cannot reference it from a different DSO. The linker can seex
(it is notstatic
), but it is not available for dynamic linkage. Documentation hereHow can it be referenced, if it's hidden?
It can't be, which is what you are being warned about. E.g. the linktime warning:
is telling you that a DSO in the linkage references the symbol
stat
, and the linker can locate a definition ofstat
in/usr/lib/libc_nonshared.a
, but (obviously) that definition is not in the DSO that references it and cannot be referenced from that DSO, because it is hidden.You get this problem if the problem DSO has not been built correctly for use as a DSO. See this example and follow the follow-ups for the solution.
Continued for OP's followups
The linker is saying:
The DSO
X
contains a reference to symbolS
. I can find a definition of symbolS
is another linked moduleY
, but that definition will not be available to satisfy the reference inX
dynamically (i.e. at runtime) becauseS
has hidden linkage inY
.You may not have explicitly marked any symbols hidden in the non-shared object. Depending on how it was built, symbols may be hidden by default unless explicitly marked otherwise.
Say the non-shared object is
libnonshared.a
and the allegedly hidden symbol isfoo
. Run:to get info about the symbols in
libnonshared.a
. In the output, look for the entry forfoo
. Does it contain the tag.hidden
? - e.g.This entry says that
foo
is a global symbol (markedg
- that's why the linker is able to see it) but it's hidden for dynamic linkage.If this turns out to be the case then you need to go and fix the build of
libnonshared.a
so that it doesn't hidefoo
. If not, then I'm stumped.