1
votes

I'm trying to build an static-linked GNU x86 binary on an 64bit CentOS system using the automake configure script. I am able able to build a static 64bit binary and a dynamic 32bit with no problems but I can't seem to figure out how to build a static 32bit binary.

I've tried the following configure command:

./configure --build=i686-pc-linux-gnu CFLAGS='-static -m32' CXXFLAGS='-static -m32'

But I get the following error message:

# ./configure --build=i686-pc-linux-gnu CFLAGS='-static -m32' CXXFLAGS='-static -m32'
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for g++... g++
checking whether the C++ compiler works... no
configure: error: in `/tmp/iperf-2.0.5':
configure: error: C++ compiler cannot create executables
See `config.log' for more details.

If I try to build just a 32bit binary passing -m32 to CFLAGS, CXXFLAGS and LDFLAGS, it works fine.

From the config.log file, I see:

configure:3104: $? = 1
configure:3124: checking whether the C++ compiler works
configure:3146: g++ -static -m32   conftest.cpp  >&5
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status

But I have both the 32 and 64bit versions of libstdc++ installed.

Any suggestions?

1

1 Answers

2
votes

For a typical autotools configure, assuming that libtool is integrated, try:

> env CFLAGS="[OPT] -m32" CXXFLAGS="[OPT] -m32" \
  ./configure --host=i686-pc-linux-gnu --enable-static [--disable-shared]

where OPT is other compiler flags, e.g., -O2, etc.

The explicit use of -static in $CFLAGS, $CXXFLAGS is probably not doing what you want.

Edit: It might actually be necessary to use: CC="gcc -m32", CXX="g++ -m32" (depending on the compiler) for the required mode to carry through to the link stage. I have encountered this before with other packages.