automake 给出错误“.la:无法识别文件:无法识别文件格式”

automake gives the error ".la: file not recognized: file format not recognized"

提问人:Fabio Porcedda 提问时间:10/2/2023 最后编辑:umläuteFabio Porcedda 更新时间:10/3/2023 访问量:37

问:

我想在 autoconf 子项目中使用 libtool 创建的库,但我得到:

$ make
[...]
gcc  -g -O2   -o test test.o liba/liba.la 
liba/liba.la: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:417: test] Error 1

文件

configure.ac

AC_INIT([test], [1.0.0])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_CONFIG_SUBDIRS([liba])
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

Makefile.am

SUBDIRS = liba
bin_PROGRAMS = test
test_SOURCES = test.c
test_LDADD = liba/liba.la

测试.c

int main()
{
}

liba/configure.ac

AC_INIT([liba], [1.0.0])
AM_INIT_AUTOMAKE([foreign subdir-objects])
LT_INIT
AC_CONFIG_FILES([Makefile])
AC_CONFIG_MACRO_DIRS([m4])
AC_OUTPUT

liba/Makefile.am

ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES = liba.la
liba_la_SOURCES = liba.c

liba/liba.c

安慰

mkdir -p liba/m4 
autoreconf -i
[...]
./configure
[...]
make
[...]
gcc  -g -O2   -o test test.o liba/liba.la 
liba/liba.la: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:417: test] Error 1

它应该是这样的:

gcc  -g -O2   -o test test.o liba/.libs/liba.so

当我将库和程序放在同一个 autoconf/automake 项目中时,它可以工作,但如果我使用子项目,则不会。

作为workaroud,如果我使用,它可以工作:但我认为这是一种解决方法,而不是一个合适的解决方案。test_LDADD = liba/.libs/liba.so

autotools autoconf automake libtool

评论


答:

0赞 Fabio Porcedda 10/2/2023 #1

要修复错误,只需在 configure.ac 中添加LT_INIT即可。

评论

0赞 ndim 10/9/2023
与所有不附带 autoconf 或 automake 的 m4 宏一样,保护并将 a 放在行上方的行中。这样可以防止在生成脚本时不可用时产生损坏的脚本的静默错误。LT_INITm4_pattern_forbid([^LT_INIT])dnlLT_INITconfigurelibtool.m4configure