Yifan Sun
Yifan Sun

Reputation: 832

Compile a m32 library in a m64 autotools project

I am creating a m64 Autotools C++ project. The main program compiles well. However, a small portion of my code need to compile a 32 bit library (not going to be used by my main program). The setting is as follows

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

When I compile the project, it gives two types of errors. First, the linker would not search for 32 bit libraries even I have gcc-multilib and g++-multilib installed. I can solve this problem by adding -L options to let the linker to search for 32 bit libraries. But this solution harms portability. Second, the Autotools add a few more 64 bits input objects such as crti.o, which causes compilation error. The full error output is here

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

Any idea how can I compile this 32 bits library with proper 32 bits system libraries?

Upvotes: 1

Views: 538

Answers (1)

olive007
olive007

Reputation: 850

First: I think you need set CFLAGS not CXXFLAGS.

CFLAGS=-m32

It's maybe nothing, but have you tried to set -m32 flags before the others ?

Second: Have you tried to use pkg-config ? You need to install it and configure PKG_CONFIG_PATH

`pkg-config --libs lib32stdc++`

http://linux.die.net/man/1/pkg-config

Sorry for my English I am learning it

Upvotes: 0

Related Questions