autotoolsautoconfautomakelibtool

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


I want to use a library created by libtool in an autoconf subproject but I get:

$ 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

Files

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

test.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

Console

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

It should be something like:

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

When I put the library and the program in the same autoconf/automake project it works but not if I use a sub project.

As workaroud it works if I use: test_LDADD = liba/.libs/liba.so but I think it's a workaround not a proper solution.


Solution

  • To fix the error just add LT_INIT in the configure.ac.