I have a hostapp.cpp
that loads a object.so
shared object at run-time, the shared object is compiled using only with the needed .h files from the host app but at run-time it needs to access those functions (present at the host app).
Compiling the host app with -rdynamic
apparently solves this issue but it unnecessarily exposes the object to the full symbol table of the host app, even though it only needs to resolve a few of them.
How can I specify exactly what host-app symbols will be known by the shared object?
Edit: I'm building and running on GNU/Linux with the GNU toolchain.
Your question is under-specified: you never said what platform you are building for, what linker you use, etc.
Assuming you build for Linux, you can specify symbols to export from the main executable using one of the following methods:
--export-dynamic-symbol
will do what you need.__attribute__((visibility("default")))
, compile with -fvisibility-hidden
, and link with -rdynamic
. That should hide most of the symbols, but will not work well if you link in libraries which you can't recompile.