首页 > 解决方案 > mingw libtool gcc 无法解析其他库中的引用

问题描述

不是我的代码(AGAR GUI),但它在 Linux 中编译正常。

现在我正在尝试在 mingw64 (Win) 中构建它,在构建其中一个库 (libag_gui.la) 时出现此错误:

.libs/**drv_sdl2.o**:drv_sdl2.c:(.rdata$.refptr.agCondEndRender[.refptr.agCondEndRender]+0x0): undefined reference to `agCondEndRender'

agCondEndRender 存在于另一个名为 ag_core 的库中,该库包含定义它的文件 time_renderer.c (.o, ,.lo)。

该库是这样构建的:

../mk/libtool/libtool --quiet --mode=link                   gcc -o **libag_core.la**                    -no-undefined -Wl,--no-undefined -XCClinker -static-libgcc                 -rpath /c/msys64/mingw64/lib                      -version-info 5:0:0
   time_win32.lo time_posix.lo **time_renderer.lo** net.lo net_dummy.lo user_win32.lo variable.lo config.lo core.lo error.lo event.lo object.lo prop.lo timeout.lo class.lo cpuinfo.lo data_source.lo load_string.lo load_version.lo vsnprintf.lo vasprintf.lo asprintf.lo dir.lo md5.lo sha1.lo rmd160.lo file.lo string.lo dso.lo tree.lo time.lo time_dummy.lo db.lo tbl.lo getopt.lo exec.lo text.lo user.lo user_dummy.lo                   -lpthread     -lwinmm

该库(ag_core)用于构建问题库,如下所示:

../mk/libtool/libtool --quiet --mode=link                   gcc -o **libag_gui.la**                     -no-undefined -Wl,--no-undefined -XCClinker -static-libgcc                 -rpath /c/msys64/mingw64/lib                      -version-info 5:0:0
   drv_sdl2_common.lo **drv_sdl2.lo** drv_gl_common.lo drv_wgl.lo drv.lo drv_sw.lo drv_mw.lo gui.lo widget.lo window.lo iconmgr.lo geometry.lo colors.lo cursors.lo ttf.lo text.lo keymap.lo keymap_latin1.lo keymap_compose.lo keysyms.lo editable.lo box.lo label.lo button.lo checkbox.lo textbox.lo radio.lo fixed_plotter.lo tlist.lo scrollbar.lo spinbutton.lo titlebar.lo toolbar.lo fspinbutton.lo combo.lo ucombo.lo units.lo nlunits.lo hsvpal.lo mspinbutton.lo mfspinbutton.lo statusbar.lo menu.lo menu_view.lo treetbl.lo separator.lo notebook.lo pixmap.lo file_dlg.lo objsel.lo fixed.lo numerical.lo table.lo glview.lo mpane.lo pane.lo console.lo graph.lo socket.lo icon.lo progress_bar.lo slider.lo text_cache.lo load_surface.lo load_color.lo load_xcf.lo file_selector.lo scrollview.lo font_selector.lo time_sdl.lo debugger.lo surface.lo widget_legacy.lo global_keys.lo input_device.lo mouse.lo keyboard.lo packedpixel.lo load_bmp.lo load_jpg.lo load_png.lo dir_dlg.lo anim.lo stylesheet.lo              **-L../core -lag_core**  -L/mingw64/lib -lSDL2 -LC:/msys64/mingw64/lib -lfreetype  -L/c/msys64/mingw64/lib -lopengl32 -lgdi32   -L/c/msys64/mingw64/lib -ljpeg -L/mingw64/lib -lpng16
-lm

(编辑:添加了 lib ag_core 的 objdump)

objdump -t libag_core.a | grep agCond 
[ 40](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x0000000000000008 agCondBeginRender 
[ 41](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x0000000000000008 agCondEndRender 
[ 42](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x0000000000000008 agCondRenderLock

objdump -t libag_core-5.dll | grep agCond
[4031](sec  6)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000000000001710 agCondEndRender
[4117](sec  6)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000000000001718 agCondRenderLock
[4330](sec  6)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000000000001720 agCondBeginRender

我不确定这个输出是什么意思,但 libag_core.a 似乎不对!为什么所有值都是 0x0...08?

这是 time_renderer.c 的前几行(似乎没有任何#ifdefs

/*  Public domain   */
/*
 * Rendering-aware time backend. This is useful for applications performing
 * offline rendering, where the outcome of the rendering may be influenced by
 * different threads, each using AG_Delay() calls or Agar timers.
 *
 * Using this backend, the start of a rendering cycle causes AG_Delay() to
 * block until the rendering cycle is complete.
 */

#include <sys/types.h>
#include <time.h>
#include <string.h>
#include <unistd.h>

#include <agar/core/core.h>

AG_Cond agCondBeginRender;
AG_Cond agCondEndRender;
AG_Mutex agCondRenderLock;

static struct timespec t0;

关于我应该看什么的任何线索?

标签: gccmingwlibtool

解决方案


原来是libtool。除非您另有说明,否则 AGAR GUI 自带它自己使用的。它包含在 AGAR 子文件夹 mk/libtool 中。

将 --with-libtool=/usr/bin/libtool (以使用其他一些 libtool)添加到 ./configure 命令行,如下所示:

./configure --host=x86_64-w64-mingw32       --prefix=$MINGWROOT       --enable-debug       --with-{freetype,sdl,png,jpeg,gl}=$MI
NGWROOT  --with-libtool=/usr/bin/libtool     --without-{fontconfig,sndfile,gettext,iconv}

您可能需要将 --tag CC 添加到 mk/build.lib.mk 中,如下所示:

LIBTOOLOPTS?=   --tag CC    --quiet

看来 AGAR 捆绑的 libtool 有点旧了!


推荐阅读