在构建共享库(取决于其他共享库)时,是否有 gcc 标志可以跳过编译时链接器对符号的解析?出于某种原因,undefined reference
当我尝试构建依赖于 B.so 和 A.so 的共享库 C 时,我的工具链会出错,即使已指定并存在依赖项。我听说存在一个 gcc 标志来延迟依赖解析到运行时。
问问题
1058 次
1 回答
2
我想你正在寻找--allow-shlib-undefined
. 从ld
手册页:
--allow-shlib-undefined
--no-allow-shlib-undefined
Allows (the default) or disallows undefined symbols in shared libraries.
This switch is similar to --no-undefined except that it determines the
behaviour when the undefined symbols are in a shared library rather than
a regular object file. It does not affect how undefined symbols in regular
object files are handled.
The reason that --allow-shlib-undefined is the default is that the shared
library being specified at link time may not be the same as the one that
is available at load time, so the symbols might actually be resolvable at
load time. Plus there are some systems, (eg BeOS) where undefined symbols
in shared libraries is normal. (The kernel patches them at load time to
select which function is most appropriate for the current architecture.
This is used for example to dynamically select an appropriate memset
function). Apparently it is also normal for HPPA shared libraries to have
undefined symbols.
不过,允许未定义的符号是默认设置,所以我猜你的问题实际上是不同的。
于 2010-02-26T00:43:59.667 回答