How, when, where to set script variables of libtool? (e.g. hardcode_minus_L)

非 Y 不嫁゛ 提交于 2019-12-13 03:12:48

问题


Long story short: I worked on relative rpath linking with this script (that uses automake, autoconf, libtool). The problem is that the final rpath/runpath entry in the binary executable or so file still has the absolute path:

  • it turned out libtool is configured by default like this with hardcode_libdir_flag_spec to include any -L value if it's set in LDFLAGS

The only question remains: how and at which point (what's the proper way) can I set other libtool variables, like hardcode_minus_L. (I've searched for it on the net, but I couldn't find anything.)

I tried to do the following:

  • after configure is called I tried to replace the value of the variable with sed in libtool file (in the proper directory): it worked but when make is called it overwrote the whole libtool file again (it was regenerated)

Note, that 2 binary files are effected by this, entry for rpath/runpath with objdump -p:

  • libcurl.so : RUNPATH /home/user1/lib/rtorrent-0.9.7-1.5.3/lib:$ORIGIN/../lib
  • rtorrent : RUNPATH $ORIGIN/../lib:/home/user1/lib/rtorrent-0.9.7-1.5.3/lib

Thanks


回答1:


I don't know if modifying the generated libtool script is the best approach to solve your problem. But if you go this way, you need to make the approach robust by executing your sed command within AC_CONFIG_COMMANDS.

The libtool script is generated during config.status as an configuration command (AC_CONFIG_COMMANDS: https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Commands) .

config.status: executing libtool commands

You can modify this generated file by adding another AC_CONFIG_COMMANDS. We use following to alter the prefer_static_libs variable:

AC_CONFIG_COMMANDS([libtool-fix-linker-preference],                                                                                                                      
    [${SED} -e '1,/prefer_static_libs=/ s/prefer_static_libs=.*$/prefer_static_libs=yes/' \
     libtool > libtool.fix && mv libtool.fix libtool])

You need to trigger your AC_CONFIG_COMMANDS after LT_INIT. configure/config.status reports the execution:

config.status: executing libtool commands
config.status: executing libtool-fix-linker-preference commands

Hope that helps,

Christian




回答2:


It turned out it's fairly easy to modify these variables in configure.ac, no need for sed - after fiddling around and taking a look into the generated scripts. The only thing can be confusing that these variables can be applied to tags defined in the given project.

E.g. to change hardcode_libdir_flag_spec to an empty value in rtorrent project (means it will break compilation), you would insert into configure.ac:

_LT_TAGVAR(hardcode_libdir_flag_spec, )=""
_LT_TAGVAR(hardcode_libdir_flag_spec, CXX)=""
_LT_TAGVAR(hardcode_minus_L, )=yes
_LT_TAGVAR(hardcode_minus_L, CXX)=yes

The 2nd parameter is the tag or default tag if it's empty.



来源:https://stackoverflow.com/questions/45282061/how-when-where-to-set-script-variables-of-libtool-e-g-hardcode-minus-l

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