如何使用autotools在64位平台上创建32位共享库

Joh*_*don 17 autotools shared-libraries

我正在使用autotools构建我的系统,主要由一个库组成.在64位Red Hat平台上,我需要能够生成一个能够在32位Red Hat平台上运行的库.

当我添加-m32到编译行时,一切都可以正常生成一个static(.a)库,但是一旦我尝试创建一个共享库,我就会得到这样的错误:

/usr/bin/ld: warning: i386:x86-64 architecture of input file `/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crti.o' is incompatible with i386 output
/usr/bin/ld: warning: i386:x86-64 architecture of input file `/usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtbeginS.o' is incompatible with i386 output  
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtbeginS.o: In function `__do_global_dtors_aux':  
crtstuff.c:(.text+0x29): undefined reference to `__DTOR_END__'  
collect2: ld returned 1 exit status' 
Run Code Online (Sandbox Code Playgroud)

我可以看到的问题是,它包括64位对象文件出来的/ usr/lib64下,而不是正确的32位的了/ usr/lib目录的(他们有正常的),但我无法弄清楚如何要解决这个问题.

vol*_*ato 14

首先,确保您具有32位编译的编译器/ libc支持.在像Ubuntu这样的发行版中,您需要做的是安装包gcc-multilib和/或g++-multilib:

sudo apt-get install gcc-multilib g++-multilib
Run Code Online (Sandbox Code Playgroud)

然后,在调用configure时,指定一个32位主机并传递32位编译标志:

./configure --host=i686-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"
Run Code Online (Sandbox Code Playgroud)

如果您没有安装multilib,则会configure: error: C compiler cannot create executables在传递-m32标志时收到错误消息.

  • 是.它成功构建了32位目标文件.当我尝试创建可共享的对象库时,会发生此问题. (2认同)