Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding AM_LDFLAGS has no effect in final library, causing linker errors

I'm using GNU autohell for my project which is a C++ library. It should link against ZMQ and boost. So I added this check for needed libraries in configure.ac

PKG_CHECK_MODULES(ZMQ, libzmq >= 3.2.3)

and linker flags in Makefile.am:

AM_LDFLAGS = -lzmq

Everything compiles and links but I got undefined reference errors when try to use library in a real application. I wondered if it really links against necessary libs or not. Surprisingly, result of ldd is like this:

ldd ./libait-0.1.0.so
    linux-vdso.so.1 =>  (0x00007fff85dfd000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fea7efa4000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fea7ebe5000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fea7e9ce000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fea7e6d2000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fea7f4d9000)

There is no link to ZMQ nor other libraries added like this. What am I doing wrong?

Update

Contents of Makefile.am

AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
#AM_LDFLAGS = -lzmq
libait_la_LIBADD = $(ZMQ_LIBS)
lib_LTLIBRARIES = libait-@[email protected]
AM_CPPFLAGS = -pipe
libait_@AIT_API_VERSION@_la_SOURCES = ....
libait_@AIT_API_VERSION@_la_LDFLAGS = -version-info $(AIT_SO_VERSION)
ait_includedir = $(includedir)/ait
ait_include_HEADERS =  ....
ait_libincludedir = $(libdir)/ait-$(AIT_API_VERSION)/include
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = ait-$(AIT_API_VERSION).pc
dist_noinst_SCRIPTS = autogen.sh
like image 736
sorush-r Avatar asked Jun 25 '26 17:06

sorush-r


1 Answers

PKG_CHECK_MODULES(ZMQ, libzmq >= 3.2.3) sets the variables: ZMQ_CFLAGS and ZMQ_LIBS.

Use AC_SUBST(ZMQ_LIBS) in configure.ac for the Makefile.am substitution variable:
libait_la_LIBADD = $(ZMQ_LIBS)

This approach lets libtool handle the library dependencies, and maintain dependency information in the libait.la file.

like image 93
Brett Hale Avatar answered Jun 27 '26 09:06

Brett Hale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!