I'm a dummy regarding C build tools, so I have a forked project to which I want to add a dynamically linked library:
https://github.com/iem-projects/ncview/tree/26c3549d165dc6047dc37db252062fd73eb9282c
Basically, what I need is to include liblo
. There is all kinds of voodoo going on for the existing libraries of the project (netcdf
for example).
I am trying to follow this manual which basically says, I should add stuff to configure.in
and Makefile.am
, then run autoreconf
, autoconf
, and automake
, then ./configure
and finally make
.
This I added to configure.in
:
# OSC support
PKG_CHECK_MODULES(LIBLO, liblo >= 0.26)
And this I added to Makefile.am
:
bin_PROGRAMS = ncview
ncview_LDADD = $(LIBLO_LIBS)
Now configure
is at least successfully checking for that library:
checking for LIBLO... yes
But make
doesn't include the library with the linker it seems:
$ make
make all-recursive
Making all in src
/usr/bin/gcc-4.2 -I/usr/X11/include -g -O2 -L/opt/local/lib -lnetcdf -lSM -lICE \
-L/usr/X11/lib -R/usr/X11/lib -lX11 -L/usr/X11/lib -R/usr/X11/lib -Wl,-rpath, -o \
ncview ncview.o file.o util.o do_buttons.o file_netcdf.o view.o do_print.o \
epic_time.o interface.o x_interface.o dataedit.o display_info.o plot_xy.o utils.o \
range.o printer_options.o overlay.o filesel.o set_options.o plot_range.o udu.o \
SciPlot.o RadioWidget.o cbar.o utCalendar2_cal.o calcalcs.o colormap_funcs.o \
make_tc_data.o stringlist.o handle_rc_file.o -lm -L/opt/local/lib -lnetcdf -lXaw \
-lXt -L/usr/X11/lib -R/usr/X11/lib -lSM -lICE -L/usr/X11/lib -R/usr/X11/lib -lX11 \
-L/usr/X11/lib -R/usr/X11/lib -lpng
Undefined symbols:
"_lo_address_new", referenced from:
_main in ncview.o
"_lo_send_internal", referenced from:
_main in ncview.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
So it links the old libraries (netcdf
, X11
), but doesn't pick up the one I added (liblo
)
This whole makefile business is black magic to me, so any clues as to why the library doesn't get linked is welcome.
Solution:
The the hint of AC_SUBST
, and looking again closer at the way the other libraries were integrated, I managed to get it working. Nothing had to be added to Makefile.am
. In configure.in
(aka configure.ac
), the following was added:
# OSC support
PKG_CHECK_MODULES(LIBLO, liblo >= 0.26)
LIBSsave=$LIBS
CFLAGSsave=$CFLAGS
CFLAGS=$LIBLO_CFLAGS
LIBS=$LIBLO_LIBS
# AC_MSG_CHECKING([for liblo OSC library])
# AC_MSG_RESULT()
# AC_CHECK_LIB(LIBLO,lo_address_new,[],[libloWorks=no])
echo "liblo OSC library: $LIBLO_LIBS"
AC_SUBST(LIBLO_CFLAGS) # si?
AC_SUBST(LIBLO_LIBS)
LIBS+=$LIBSsave
CFLAGS+=$CFLAGSsave