What is the equivalent of --as--needed in macOS linker? - Stack Overflow

On Linux, the linker option --as-needed is used to avoid keeping a reference to an unused library.With

On Linux, the linker option --as-needed is used to avoid keeping a reference to an unused library.

With this option, if -lxyz is used in the link command but no symbol from libxyz.so is used in the application, the executable will not load libxyz.so. Conversely, with the linker option --no-as-needed, the library will be loaded even if none of its symbols is referenced in the application. The default depends on the distro (see my previous question here).

What would be the equivalent option on macOS?

On macOS, the options --as-needed and --no-as-needed do not exist. The default behaviour is equivalent to --no-as-needed, the libraries which were mentioned in the link command line are all loaded, even without symbol reference from the application. The command otool -L on the executable always lists all libraries.

I cannot find any option to avoid loading unused libraries, no equivalent to --as-needed.

On Linux, the linker option --as-needed is used to avoid keeping a reference to an unused library.

With this option, if -lxyz is used in the link command but no symbol from libxyz.so is used in the application, the executable will not load libxyz.so. Conversely, with the linker option --no-as-needed, the library will be loaded even if none of its symbols is referenced in the application. The default depends on the distro (see my previous question here).

What would be the equivalent option on macOS?

On macOS, the options --as-needed and --no-as-needed do not exist. The default behaviour is equivalent to --no-as-needed, the libraries which were mentioned in the link command line are all loaded, even without symbol reference from the application. The command otool -L on the executable always lists all libraries.

I cannot find any option to avoid loading unused libraries, no equivalent to --as-needed.

Share Improve this question asked Feb 2 at 21:05 Thierry LelegardThierry Lelegard 7513 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Answering my own question after a few days of research:

  • Linker option: -dead_strip_dylibs
  • Or from the clang command: -Wl,-dead_strip_dylibs

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745256383a4618981.html

相关推荐

  • What is the equivalent of --as--needed in macOS linker? - Stack Overflow

    On Linux, the linker option --as-needed is used to avoid keeping a reference to an unused library.With

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信