【问题标题】:Makefile.am: How to link a dynamic library only if the library exists/is installed on the systemMakefile.am:仅当库存在/安装在系统上时如何链接动态库
【发布时间】:2023-01-09 06:36:22
【问题描述】:

我有一个动态库/usr/lib64/liba-3.2.so.1。而且,我正在尝试更改 Makefile.am,以便 myprog_LDADD 可以链接到该库(如果该文件存在)。有什么办法吗?

我试过这个:

if [ -f /usr/lib64/liba-3.2.so.1 ]; then myprog_LDADD += /usr/lib64/liba-3.2.so.1 ; fi;

但这是行不通的。如果库存在,关于如何使 Makefile.am 链接到库的任何建议?谢谢!

【问题讨论】:

  • 如果系统没有有那个图书馆吗?符号将如何解决,否则将针对图书馆解决?
  • 我不清楚你到底在追求什么,因为你所描述的内容本身没有意义。但这里有一些建议的搜索词:automake conditional。

标签: makefile gnu-make gnu configure automake


【解决方案1】:

通常的方法当然是使用您的configure(.ac)(autotools)来检查库是否存在,然后使用结果告诉您的Makefile(.am)链接到库。

来自configure.ac的片段:

AC_CHECK_LIB([a-3.2], [a_fun], [A_LIBS="-la-3.2"])
AC_SUBST([A_LIBS])

以及来自Makefile.am 的相应 sn-p:

myprog_LDADD += @A_LIBS@

请注意,这将在链接器的所有(默认)搜索路径中查找 liba-3.2.so,并且没有 .1 后缀,但我认为无论如何这是正确的行为(并且您针对 /usr/lib64/liba-3.2.so.1 的显式链接必须在从非 64 位平台开始的多个场景中失败,所以我认为这种过度适应)

【讨论】:

    猜你喜欢
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-06
    • 1970-01-01
    相关资源
    最近更新 更多