我正在创建一个m64 Autotools C ++项目。主程序汇编得很好。但是,我的一小部分代码需要编译一个32位的库(不会被我的主程序使用)。设置如下
lib_LTLIBRARIES = $(top_builddir)/lib/libabc.la
__top_builddir__lib_libabc_la_LDFLAGS = -version-info 1:0:0 -m32
__top_builddir__lib_libabc_la_SOURCES = \
abc.cc
AM_CXXFLAGS = -m32
endif
当我编译项目时,它会产生两种类型的错误。首先,即使我安装了gcc-multilib和g ++ - multilib,链接器也不会搜索32位库。我可以通过添加-L选项来让链接器搜索32位库来解决这个问题。但这种解决方案会损害可移植性。其次,Autotools添加了一些64位输入对象,例如crti.o,这会导致编译错误。完整的错误输出在这里
libtool: link: g++ -fPIC -DPIC -shared -nostdlib /usr/lib/gcc/x86_64-linux-
gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-
gnu/4.8/crtbeginS.o .libs/abc.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -
L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -
L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu -
L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -
L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. -lstdc++ -lm -lc -lgcc_s
/usr/lib/gcc/x86_64-linux-gnu/4.8/crtendS.o /usr/lib/gcc/x86_64-linux-
gnu/4.8/../../../x86_64-linux-gnu/crtn.o -m32 -msse2 -O0 -m32 -Wl,-soname -
Wl,libabc.so.1 -o ../../lib/.libs/libabc.so.1.0.0
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libm.a when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.a when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libc.a when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.a when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/lib/gcc/x86_64-linux-gnu/4.8/crtbeginS.o' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/lib/gcc/x86_64-linux-gnu/4.8/crtendS.o' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o' is incompatible with i386 output
collect2: error: ld returned 1 exit status
任何想法如何用适当的32位系统库编译这个32位库?
答案 0 :(得分:0)
首先:我认为你需要设置CFLAGS而不是CXXFLAGS。
CFLAGS=-m32
它可能没什么,但你试过在其他人之前设置-m32标志吗?
第二:您是否尝试过使用pkg-config?您需要安装它并配置PKG_CONFIG_PATH
`pkg-config --libs lib32stdc++`
http://linux.die.net/man/1/pkg-config
对不起我的英语我正在学习