How do I link a shared library with --as-needed with automake?

混江龙づ霸主 提交于 2019-12-10 16:16:59

问题


How do I link a shared library with --as-needed using Automake? When I tried adding the flag to LDFLAGS, I saw libtool called as so:

/bin/bash ../../libtool --mode=link ... -Wl,--as-needed ... dependencies

Which results in a call to GCC like so:

gcc -shared ... dependencies ... -Wl,--as-needed ...

But that's the wrong order.

  • Is there a way to do this with Libtool?

  • Or is there a nice way to build shared libraries using Automake but without Libtool? (I've been frustrated at Libtool for various other reasons in the past...)

It seems the Debian folks ran into this problem too (bug report) but I'd like to be able to fix this for my project rather than messing with my system (unless I misunderstand the fix).


回答1:


You can fix that just for your project by modifying the ltmain.sh script in your project sources. You can even add it as part of autotools bootstrapping, as in: https://meego.gitorious.org/tracker/tracker/commit/cf2ca3414aeba146dceacc5ecd84765f4c08a06f




回答2:


You can fix it in Makefile.am; basically it's the same as the answer to my question here, except you need to use -(no-)as-needed instead of -(no-)whole-archive.




回答3:


Really a frustrating issue, especially for package maintennance.

Debian has built in support to patch libtool and fix this problem in debian packages

dh_autoreconf --as-needed

Or, if you're using CDBS:

include /usr/share/cdbs/1/rules/autoreconf.mk

DEB_DH_AUTORECONF_ARGS += --as-needed


来源:https://stackoverflow.com/questions/6852414/how-do-i-link-a-shared-library-with-as-needed-with-automake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!