简体   繁体   English

将库添加到自动工具文件不起作用(链接器将其忽略)

[英]Adding a library to autotools files does not work (linker ignores it)

I'm a dummy regarding C build tools, so I have a forked project to which I want to add a dynamically linked library: 我是C构建工具的虚拟人物,所以我有一个分支的项目,我想向其中添加动态链接的库:

https://github.com/iem-projects/ncview/tree/26c3549d165dc6047dc37db252062fd73eb9282c https://github.com/iem-projects/ncview/tree/26c3549d165dc6047dc37db252062fd73eb9282c

Basically, what I need is to include liblo . 基本上,我需要包含liblo There is all kinds of voodoo going on for the existing libraries of the project ( netcdf for example). 项目的现有库(例如netcdf )正在使用各种伏都netcdf

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 . 我试图遵循该手册该手册基本上说:我应该在configure.inMakefile.am添加一些内容,然后运行autoreconfautoconfautomake ,然后运行./configure并最终make

This I added to configure.in : 我添加到configure.in

# OSC support
PKG_CHECK_MODULES(LIBLO, liblo >= 0.26)

And this I added to Makefile.am : 这是我添加到Makefile.am

bin_PROGRAMS = ncview

ncview_LDADD = $(LIBLO_LIBS)

Now configure is at least successfully checking for that library: 现在configure至少可以成功检查该库:

checking for LIBLO... yes

But make doesn't include the library with the linker it seems: 但是make似乎没有包含链接器的库:

$ 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 ) 因此,它链接了旧的库( netcdfX11 ),但没有选择我添加的库( liblo

This whole makefile business is black magic to me, so any clues as to why the library doesn't get linked is welcome. 整个makefile业务对我来说都是不可思议的,因此欢迎提供任何有关为什么未链接库的线索。


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. AC_SUBST的提示下,再次仔细查看其他库的集成方式,我设法使其正常工作。 Nothing had to be added to Makefile.am . 无需添加任何内容到Makefile.am In configure.in (aka configure.ac ), the following was added: configure.in (又名configure.ac )中,添加了以下内容:

# 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

After PKG_CHECK_MODULES , the variables LIBIO_CFLAGS and LIBIO_LIBS should be defined. PKG_CHECK_MODULES之后,应定义变量LIBIO_CFLAGSLIBIO_LIBS At this point, you should add: 此时,您应该添加:

AC_SUBST(LIBIO_CFLAGS)
AC_SUBST(LIBIO_LIBS)

to the configure.ac file. configure.ac文件。 The Makefile.am then needs to make use of these substitutions: 然后, Makefile.am需要使用以下替换:

ncview_CPPFLAGS = $(LIBIO_CFLAGS)
ncview_LDADD = $(LIBIO_LIBS)

you can also directly substitute the value of LIBLO-flags with a syntax like: 您还可以使用以下语法直接替换LIBLO-flags的值:

configure.ac: configure.ac:

  PKG_CHECK_MODULES(LIBLO, liblo >= 0.26)

Makefile.am: 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) 您还应注意不要覆盖LDADD的先前值(反之亦然,因此您的值将被覆盖)

  ncview_LDADD = @LIBLO_LIBS@
  ncview_LDADD = -lm

should give you a warning and @LIBLO_LIBS@ will have no effect. 应该给您一个警告,@ LIBLO_LIBS @无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM