Linux下成功编译32位动态库GNU-pth的方法求助
在Ubuntu 24.04编译32位GNU Pth动态库的问题
环境信息
- 系统:Ubuntu 24.04.2(虚拟机)
- 工具链:gcc 13.3.0、ldd 2.39、gcc-multilib 4:13.2.0-7ubuntu1
- 源码:GNU Pth 2.0.7
- 前置情况:已成功编译该库的32位静态版本,但动态库编译时出现以下问题
问题1:指定架构参数后,configure强制生成静态库
执行configure命令:
./configure --build=i386 --disable-static --prefix=<out dir> --with-mctx-mth=sjlj --with-mctx-dsp=ssjlj --with-mctx-stk=sas CFLAGS="-m32 -pthread -fno-stack-protector" LDFLAGS="-m32 -pthread"
输出关键错误:
checking whether to build static libraries... yes configure: creating libtool appending configuration tag "CXX" to libtool checking for ld used by g++... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking whether the g++ linker (/usr/bin/ld) supports shared libraries... no
问题2:不指定架构参数但保留-m32,编译时出现架构不兼容与链接错误
执行configure时不添加--build或--host参数,仅保留-m32编译标志,configure允许构建带elf_i386标志的动态库,但编译阶段报错:
/usr/bin/ld: i386 architecture of input file `.libs/pth_debug.o' is incompatible with i386:x86-64 output /usr/bin/ld: i386 architecture of input file `.libs/pth_ring.o' is incompatible with i386:x86-64 output /usr/bin/ld: i386 architecture of input file `.libs/pth_pqueue.o' is incompatible with i386:x86-64 output
同时伴随链接未定义符号与格式错误:
/usr/bin/ld: .libs/pth_string.o: in function `fmtint': pth_string.c:(.text+0x928): undefined reference to `__umoddi3' /usr/bin/ld: pth_string.c:(.text+0x955): undefined reference to `__udivdi3' /usr/bin/ld: .libs/pth_debug.o: file class ELFCLASS32 incompatible with ELFCLASS64 /usr/bin/ld: final link failed: file in wrong format collect2: error: ld returned 1 exit status make: *** [Makefile:171: libpth.la] Error
补充信息
无论在--host或--target中指定i386,configure都会接受构建动态库的请求,但编译sanity测试时,库文件与测试程序仍存在兼容性问题,相关configure输出:
checking whether the gcc linker (/usr/bin/ld -m elf_i386) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... no
恳请提供解决帮助。
内容的提问来源于stack exchange,提问作者Marc St-Jacques
相关产品推荐
相关产品推荐

