4
votes

I am building an x86_64-elf kernel on OS X. My build system is autotools. I successfully compiled gcc to cross-compile for x86_64-elf on OS X. When I run the configure script generated from autotools I have an issue:

configure: error: C compiler cannot create executables
See `config.log' for more details

So I look at config.log and see:

cannot find crt0.o: No such file or directory
collect2: error: ld returned 1 exit status

This makes perfect sense. The cross-compiler won't generate an executable because there is no associated runtime. But I don't need or want my compiler to generate an executable, I'm going to link it appropriately for my bootloader. How do I tell autotools to not check this?

2
Can't you just set the CC variable in your configure.ac script? It might not work however, as other tests may create executable files that the script tries to run. - Some programmer dude
I set the CC variable when I run configure, its really bad form to set it in configure.ac. Regardless, that doesn't answer the question of how I get it to stop checking if the compiler can create executables. - dschatz
Tell configure that you are cross-compiling. Use ./configure --host=x86_64-unknown-linux. If the build type is different from the host type, certain tests may be skipped. - jørgensen
I am doing that, --host=x86_64-elf, it still fails. - dschatz

2 Answers

3
votes

Make sure that you are specifying the following gcc flags when you run the configure script (add them to the CFLAGS environment variable):

-nostdlib -nostartfiles -nodefaultlibs -ffreestanding

If you don't know how to append these to the end of CFLAGS, try something like:

export CFLAGS=$CFLAGS -nostdlib -nostartfiles -nodefaultlibs -ffreestanding
0
votes

Try:

DARWIN_VERSION_FULL=darwin`uname -r`
./configure --build=x86_64-apple-${DARWIN_VERSION_FULL} --host=x86_64-unknown-linux

Now configure should be in cross compiling mode, and stop running that test.