Shanker Wang
Shanker Wang

Reputation: 43

Cross-compile gcc on OS X failed: cannot compute suffix of object files: cannot compile

I'm trying to cross-compile i386-elf-gcc on OS X 10.9 using

./configure --enable-languages=c,c++,fortran,go,java,objc,obj-c++ \
            --enable-stage1-languages=c++ \
            --prefix=/usr/local/i386-efi-gcc --target=i386-elf

and

make -j 16

Finally I got such an error:

checking for suffix of object files... configure: error: in `/src/gcc-4.9.1/i386-elf/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
Makefile:10818: recipe for target 'configure-target-libgcc' failed
make[1]: *** [configure-target-libgcc] Error 1
make[1]: Leaving directory '/src/gcc-4.9.1'
Makefile:874: recipe for target 'all' failed
make: *** [all] Error 2

I checked out /src/gcc-4.9.1/i386-elf/libgcc/config.log:

configure:3580: checking for suffix of object files
configure:3602: /src/gcc-4.9.1/host-x86_64-apple-darwin13.3.0/gcc/xgcc -B/src/gcc-4.9.1/host-x86_64-apple-darwin13.3.0/gcc/ -B/usr/local/i386-efi-gcc/i386-elf/bin/ -B/usr/local/i386-efi-gcc/i386-elf/lib/ -isystem /usr/local/i386-efi-gcc/i386-elf/include -isystem /usr/local/i386-efi-gcc/i386-elf/sys-include    -c -g -O2  conftest.c >&5
/src/gcc-4.9.1/host-x86_64-apple-darwin13.3.0/gcc/as: line 106: exec: -o: invalid option
exec: usage: exec [-cl] [-a name] file [redirection ...]
configure:3606: $? = 1

I realize there may be something wrong with /src/gcc-4.9.1/host-x86_64-apple-darwin13.3.0/gcc/as. Below is what I see in the beginning of it:

# Invoke as, ld or nm from the build tree.

ORIGINAL_AS_FOR_TARGET=""
ORIGINAL_LD_FOR_TARGET=""
ORIGINAL_LD_BFD_FOR_TARGET="/.bfd"
ORIGINAL_LD_GOLD_FOR_TARGET="/.gold"
ORIGINAL_PLUGIN_LD_FOR_TARGET=""
ORIGINAL_NM_FOR_TARGET=""

Apparently, ORIGINAL_AS_FOR_TARGET shouldn't be empty. Since the as script is generated by gcc-4.9.1/gcc/configure, I checked out gcc-4.9.1/host-x86_64-apple-darwin13.3.0/gcc/config.log and found out:

configure:21319: checking for i386-elf-as
configure:21352: result: no
configure:21368: checking what assembler to use
configure:21409: result: 
configure:21483: checking for i386-elf-ld
configure:21516: result: no
configure:21549: checking whether we are using gold
configure:21558: result: no
configure:21569: checking what linker to use
configure:21603: result: 
configure:21631: checking for i386-elf-nm
configure:21664: result: no
configure:21672: checking what nm to use
configure:21680: result: 
configure:21711: checking for i386-elf-objdump
configure:21744: result: no
configure:21752: checking what objdump to use
configure:21759: result: not found
configure:21781: checking for readelf
configure:21799: found /usr/local/bin/readelf
configure:21811: result: /usr/local/bin/readelf
configure:21822: checking what readelf to use
configure:21832: result: /usr/local/bin/readelf

I think maybe things were going wrong here.

Why the error occurs and how can I successfully cross-compile gcc?

Upvotes: 4

Views: 1949

Answers (1)

Markku Kero
Markku Kero

Reputation: 391

A major prerequisite for compiling gcc is to have compiled a corresponding binutils package for the same target first. You can get the latest binutils here:

http://ftp.gnu.org/gnu/binutils/

Frist compile and install the binutils package using the same target prefix (and make sure it will provide you with i386-elf-as, i386-elf-ld, etc.). Then start from a clean slate with your gcc build (= remove the directory where your build failed and extract the files again). Just make sure your binutils binaries are in PATH when you run your ./configure.

Hopefully that will get you forward.

Upvotes: 3

Related Questions