【问题标题】:specifying optional library for gcc linker为 gcc 链接器指定可选库
【发布时间】:2012-04-15 09:54:24
【问题描述】:

gcc (g++) 链接器是否支持一个选项,允许它在无法找到提供给它的某些库时不会失败? 谢谢, 拉菲

【问题讨论】:

  • 这样做有什么意义?
  • 除了失败还能做什么?
  • 欢迎来到 Stack Overflow。我自己也时不时遇到这个问题。
  • 我们假设您的意思是与共享库对象的链接在链接时丢失但在运行时存在,对吗?

标签: gcc linker


【解决方案1】:

听起来你想要的是来自 ld 手册页的内容:

--allow-shlib-undefined
--no-allow-shlib-undefined
Allows 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 default behaviour is to report errors for any undefined symbols referenced in shared libraries if the linker is being used to create an executable, but to allow them if the linker is being used to create a shared library.

The reasons for allowing undefined symbol references in shared libraries specified at link time are that: 
• A shared library specified at link time may not be the same as the one that is available at load time, so the symbol might actually be resolvable at load time.

• There are some operating systems, eg BeOS and HPPA , where undefined symbols in shared libraries are normal. 
The BeOS kernel for example patches shared libraries at load time to select whichever function is most appropriate for the current architecture. This is used, for example, to dynamically select an appropriate memset function. 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-27
    • 2016-02-12
    相关资源
    最近更新 更多