在构建具有依赖项的Linux共享库时,跳过编译时符号解析

时间:2010-02-26 00:32:59

标签: c++ linux linker libraries shared

在构建共享库时(取决于其他共享库),是否有一个gcc标志来跳过编译时链接器对符号的解析?出于某种原因,当我尝试构建依赖于B.so和A.so的共享库C时,我的工具链会出现undefined reference错误,即使指定并存在依赖项。我听说存在一个gcc标志来将依赖项解析延迟到运行时。

1 个答案:

答案 0 :(得分:2)

我认为你正在寻找--allow-shlib-undefined。来自ld man page

--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.

允许使用未定义的符号是默认符号,所以我猜你的问题实际上是不同的。