Reputation: 2290
I have an executable which links to a static library. The library exposes a symbol create_widget(). This symbol is not linked into the executable by clang because it is not referenced by the executable.
The executable links to another library which, at runtime, can reference any symbol exposed by the executable. I need to let this library see create_widget().
Is there a good way to resolve this? If not, i'll share the source code for create_widget() with all of the executables that need it instead of bundling it in a library.
Upvotes: 3
Views: 2138
Reputation: 61232
There are two ways you can do it:-
1) Link the object file that exports create_widget()
explicitly, rather
than from a library. That way any symbols it exports will be linked whether
they are referenced or not.
2) Link the static library (say it's libwidget.a
) with the options --whole-archive -lwidget --no-whole-archive
.
That way, every object file in libwidget
will be linked whether it contains any
referenced symbols or not.
Upvotes: 4