【问题标题】:Skip compile-time symbol resolution when building Linux shared libraries with dependencies构建具有依赖项的 Linux 共享库时跳过编译时符号解析
【发布时间】:2011-01-21 06:36:59
【问题描述】:

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

【问题讨论】:

    标签: c++ linux linker libraries shared


    【解决方案1】:

    我认为您正在寻找--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.
    

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

    【讨论】:

      猜你喜欢
      • 2015-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多