autotools - LDFLAGS 在带有 libtool 的自动工具中的使用

标签 autotools libtool ldflags

根据操作系统的不同,我在configure.ac中定义了一个特殊的LDFLAGS:

AC_CANONICAL_HOST
if test "$host_os" = cygwin
then
    LDFLAGS="$LDFLAGS -Wl,-no-undefined"
    export LDFLAGS
fi
AC_SUBST([LDFLAGS])

该包使用 AC_PROG_LIBTOOL,并且当 LDFLAGS 传递给 libtool 时,-Wl 前缀保留,链接器无法理解选项。如果我删除此前缀,AC_PROG_CXX 宏就会失败,因为 GCC 会因 -no-undefined 本身而阻塞。我做错了什么?

LDFLAGS 未提及 Makefile.am,但我已通过运行 make -n 确保在 libtool 命令中尊重它>.

我在 Cygwin 1.7.28(0.271/5/3) 下使用 autoconf 2.69、automake 1.14、gmake 4.0 和 gcc 4.8.2

编辑:我有几十个 Makefile.am,其中一半以上来自外部库 - 我更喜欢从中央位置控制这些标志。

最佳答案

Libtool 有一个 -no-undefined 选项。

GNU ld 有一个 --no-undefined 选项。

您应该让 libtool 从 Makefile.am 内部了解它,并让它负责转发到链接器:

configure.ac

AC_CANONICAL_HOST
if test "$host_os" = cygwin
then
    EXTRA_LDFLAGS="-no-undefined"
fi
AC_SUBST([EXTRA_LDFLAGS])

Makefile.am

AM_LDFLAGS = $(EXTRA_LDFLAGS) ...

作为一般规则,您不应该乱用configure.ac 中的CPPFLAGS、LDFLAGS 等,因为用户可能需要在调用“make”时更改它们。

关于autotools - LDFLAGS 在带有 libtool 的自动工具中的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21840315/

相关文章:

c - 未找到 Automake 错误 './ltmain.sh'

autotools - 使用 automake 配置脚本在 64 位 Linux 上构建 32 位?

c++11 - AX_CXX_COMPILE_STDCXX_11 不起作用 : syntax error near unexpected token `,'

Docker Alpine 错误 : possibly undefined macro: AC_PROG_LIBTOOL

c - 为什么 gcc 失败并显示 'unrecognized command line option "-L/lusr/opt/mpfr-2.4.2/lib"'?

go - 如何在 golang 中使用 LDFLAGS 的相对路径

makefile - 如何在 makefile 中使用 LDFLAGS

solaris - Automake:变量在 Solaris 上未扩展

c - `configure.ac` 文件给出错误

linux - 在构建期间将静态库链接到共享库?