is there a way to ensure that clang links an unreferenced library symbol

时间:2015-09-29 00:41:59

标签: linker export clang symbols

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.

1 个答案:

答案 0 :(得分:2)

有两种方法可以做到: -

1)链接显式导出create_widget()目标文件 而不是从图书馆。这样,它导出的任何符号都将被链接 它们是否被引用。

2)将静态库(比如libwidget.a)与选项--whole-archive -lwidget --no-whole-archive相关联。 这样,libwidget中的每个目标文件都将被链接,无论它是否包含任何目标文件 是否引用了符号。

相关问题