0

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
0__
  • 66,707
  • 21
  • 171
  • 266
  • For a start, if a guide is still referring to `configure.in` instead of [`configure.ac`](http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Writing-Autoconf-Input.html#Writing-Autoconf-Input), it is hopelessly out of date. – Brett Hale Jan 18 '13 at 13:15
  • @BrettHale - no, the guide says "configure.ac, formerly known as configure.in", but in the project that concrete file is "configure.in", yes it's an old project (not written by myself) – 0__ Jan 18 '13 at 13:24
  • Unfortunately, there's no entry level `configure.ac`. It requires a lot of know-how to get anything useful done; either by looking at a lot of existing source, or [better tutorials](http://www.freesoftwaremagazine.com/books/autotools_a_guide_to_autoconf_automake_libtool). – Brett Hale Jan 18 '13 at 13:48
  • are you sure about the "+=" (e.g. `LIBS+=`) in your solution-configure.in? – umläute Jan 19 '13 at 18:44

2 Answers2

2

After PKG_CHECK_MODULES, the variables LIBIO_CFLAGS and LIBIO_LIBS should be defined. At this point, you should add:

AC_SUBST(LIBIO_CFLAGS)
AC_SUBST(LIBIO_LIBS)

to the configure.ac file. The Makefile.am then needs to make use of these substitutions:

ncview_CPPFLAGS = $(LIBIO_CFLAGS)
ncview_LDADD = $(LIBIO_LIBS)
Brett Hale
  • 21,653
  • 2
  • 61
  • 90
  • Thanks. I saw those `AC_SUBST` calls before. There is still a problem with the `ncview_` prefix approach: `automake: warning: compiling 'ncview.c' with per-target flags requires 'AM_PROG_CC_C_O' in 'configure.in'`. However, I managed to get the whole thing going and will update the question. I will check your answer, because I think the `AC_SUBST` was the crucial bit. – 0__ Jan 18 '13 at 14:38
  • add `AM_PROG_CC_C_O` to your configure.in in order to get rid of the warning (this is what it is trying to tell you: it requires this macro somewhere in configure.ac) – umläute Jan 19 '13 at 18:45
1

you can also directly substitute the value of LIBLO-flags with a syntax like:

configure.ac:

  PKG_CHECK_MODULES(LIBLO, liblo >= 0.26)

Makefile.am:

  ncview_LDADD += @LIBLO_LIBS@

you should also take care not to overwrite previous values of LDADD (or the other way round, so your values get overwritten)

  ncview_LDADD = @LIBLO_LIBS@
  ncview_LDADD = -lm

should give you a warning and @LIBLO_LIBS@ will have no effect.

umläute
  • 28,885
  • 9
  • 68
  • 122
  • Thank you! As with the other answer, there is a problem with the `ncview_` prefix. If I change `=` for `+=`, automake just says the `+=` operator can only be used if there was a previous value assigned, which wasn't the case. – 0__ Jan 18 '13 at 14:39
  • ...but I could use the `+=` finally (see amended question) – 0__ Jan 18 '13 at 14:52