How to satisfy dependencies for static compilation of 'dialog' tool for 32-bit

时间:2018-03-23 15:39:20

标签: linux gcc undefined-reference

I want to compile the dialog程序中的背景颜色和文本颜色更改为64位Ubuntu(16.04)中的32位和静态链接可执行文件。这使得它可以轻松地在makeself存档中分发,而不必担心依赖性等。我已经在3年前建立了这种方式并且还记下了如何做到这一点:

# get source and build-deps, then run:
./configure CFLAGS="-m32" LDFLAGS="-m32 -static"
make

现在我修改了源代码(添加了附加选项),但重建失败,抱怨未定义对Gpm_***函数的引用。这与我的修改无关。链接阶段:

gcc -o dialog dialog.o -L. -ldialog -Wl,-rpath,/lib64   -L/lib64 -m32 -static -lncurses -ltermcap -lm 
/usr/lib/gcc/x86_64-linux-gnu/5/../../../i386-linux-gnu/libncurses.a(lib_mouse.o): In function `_nc_mouse_event':
(.text+0x632): undefined reference to `Gpm_GetEvent'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../i386-linux-gnu/libncurses.a(lib_mouse.o): In function `enable_gpm_mouse':
(.text+0xcd2): undefined reference to `Gpm_Close'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../i386-linux-gnu/libncurses.a(lib_mouse.o): In function `enable_gpm_mouse':
(.text+0xd22): undefined reference to `Gpm_Open'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../i386-linux-gnu/libncurses.a(lib_mouse.o): In function `enable_gpm_mouse':
(.text+0xd3a): undefined reference to `Gpm_Close'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../i386-linux-gnu/libncurses.a(lib_mouse.o): In function `_nc_mouse_init':
(.text+0xe8c): undefined reference to `gpm_fd'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../i386-linux-gnu/libncurses.a(lib_mouse.o): In function `mouse_activate':
(.text+0x1061): undefined reference to `gpm_fd'
collect2: error: ld returned 1 exit status
makefile:211: recipe for target 'dialog' failed
make: *** [dialog] Error 1

链接器选择libncurses.a,这对我来说似乎没问题,因为它是一个静态库存档。我不明白为什么找不到Gpm _ ***函数。 libgpm.a提供这些并且位于同一目录中。即使配置为向LDFLAGS添加/usr/lib/i386-linux-gnu/libgpm.a也没有效果。

如何使其成功链接?

更新:

在此处查看详细链接(-Wl,--verbose)的结果:https://pastebin.com/AP48KMGt

1 个答案:

答案 0 :(得分:2)

在安装gcc-multilib(当然)和libncurses5libtinfolibgpm的i386开发包之后,它适用于我:

sudo apt install gcc-multilib libncurses5-dev:i386 libtinfo-dev:i386 libgpm-dev:i386

并明确地与他们联系:

gcc -o dialog dialog.o -L. -ldialog -g -O2 -m32 -static -lncurses -ltinfo -lgpm -lm

我得到./configure根据您的示例生成一个有效的Makefile,其中包含

$ ./configure CFLAGS="-m32" LDFLAGS="-m32 -static" LIBS="-lgpm"
$ make
...
gcc -o dialog dialog.o -L. -ldialog -m32 -Wl,-rpath,/lib64   -L/lib64 -m32 -static -lncurses -ltermcap -lm -lgpm

结果似乎是有效的i386可执行文件:

$ file dialog
dialog: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=4cbdb45a86cb5e6859db8c7cbeeaaa49baf45718, not stripped

注意:我尝试将--host=i686-linux-gnu--host=i686-pc-linux-gnu--host=i386-linux-gnu--host=i386-pc-linux-gnu传递给./configure,但它没有任何区别。