Is it possible to link to a shared library without access to the library itself?

Viewed 2446

I have the header files of a shared library but not the shared library nor its source code.

Can I still compile some code against this library?

If not, what information does the shared library contain which is not in the headers?

3 Answers

For those who just want it done, aside from using a dummy lib, there is another (probably even less robust) option: patchelf

Execute the following command after linking complete

patchelf --add-needed missinglib.so mylib.so

For CMake users, this can be done automatically by adding

add_custom_command(
    TARGET mylib POST_BUILD
    COMMAND patchelf --add-needed missinglib.so "$<TARGET_FILE:mylib>")
Related