Page 1 of 1

Cross Compiling for win32

Posted: Thu Dec 30, 2010 11:24 pm
by hibbity
Running ubuntu 9.04, trying to create a cross-compile toolchain for 32-bit Windows target.

Looking at the options available, what would be the best/most robust/recommended method:

1) Follow the tutorial at: http://wiki.osdev.org/OS_Specific_Toolchain
2) Follow the steps here: http://wiki.osdev.org/GCC_Cross-Compiler
3) Try the 'boomstick' method: http://wiki.osdev.org/Boomstick

Second, what would be the proper target specification (cpu-platform-os) for the building process.
Would it be something like, "i586-elf-gcc"? "i686-ia32-gcc"?

Third, I have downloaded binutils-2.21, gcc-4.5.2, and glibc-2.12.2.
Should I avoid these in favor of binutils-2.20.1 and gcc-4.5.1 as per the table: http://wiki.osdev.org/Cross-Compiler_Successful_Builds

Thanks.

Re: Cross Compiling for win32

Posted: Thu Dec 30, 2010 11:40 pm
by Brynet-Inc
So wait, you want to compile a cross compiler on Ubuntu that runs on Windows but generates ELF executables?

Re: Cross Compiling for win32

Posted: Fri Dec 31, 2010 1:37 am
by xenos
I guess Win32 target rather means that the compiler runs on Ubuntu and produces Win32 executables - otherwise it would be Win32 host and ELF target (and that would be a Canadian Cross),

So I guess in this case the target triplet would be something like i686-pc-cygwin or i686-pc-mingw, but this is just a shot in the dark. I haven't used Windows for a while, and I never used a cross compiler for creating Win32 executables.

Re: Cross Compiling for win32

Posted: Fri Dec 31, 2010 8:40 am
by Solar
If you really want to target Windows, your best bet would be to look what your package manager offers you with regards to the search keyphrase "mingw".

Targeting Windows requires not only a cross-compiler, but also the necessary runtime files and libraries, all of which come nicely bundled in the MinGW package.

Re: Cross Compiling for win32

Posted: Fri Dec 31, 2010 11:26 am
by hibbity
Looking at http://wiki.osdev.org/Canadian_Cross, this is useful info.

Then to target win32 executables, for triplet specifications, I would probably use:
--build=<where this compiler runs> i686-pc-linux-gnu (build os is "linux-gnu")
--host=<where the compiler you're building shall run> i686-pc-linux-gnu (host os is "linux-gnu")
--target=<where the executables the compiler you're building will build shall run> i686-pc-mingw32

This is my best guess, based on info in (binutils/ or gcc/) config.guess and in the generated Makefiles.

Re: Cross Compiling for win32

Posted: Fri Dec 31, 2010 3:03 pm
by hibbity
With these settings, building and installing binutils 2.21 works fine, as does building and installing gcc 4.5.2.
When completed, the newly built compiler (i686-pc-mingw32-gcc) can be invoked with ${TARGET}-gcc

The next step, "make all-target-libgcc" fails:
In file included from ../.././gcc/tm.h:11:0,
from ../../../gcc-4.5.2/libgcc/../gcc/libgcc2.c:31:
../../../gcc-4.5.2/libgcc/../gcc/config/i386/cygming.h:103:19: fatal error: stdio.h: No such file or directory
compilation terminated.
make[1]: *** [_muldi3.o] Error 1

At this point, neither has glibc-2.12.2 been built. Running:
sudo CC=${TARGET}-gcc ../glibc-2.12.2/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=$TARGET --prefix=$PREFIX --with-headers=${TARGET_PREFIX}/include

...results in:
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for i686-pc-linux-gnu-gcc... i686-pc-mingw32-gcc
checking for suffix of object files... configure: error: in `/home/crossbuild/build-glibc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.

Inside config.log, we find:

../glibc-2.12.2/configure: line 2424: i686-pc-mingw32-gcc: command not found
configure:2426: $? = 127
configure:2433: i686-pc-mingw32-gcc -v >&5
../glibc-2.12.2/configure: line 2435: i686-pc-mingw32-gcc: command not found
configure:2437: $? = 127
configure:2444: i686-pc-mingw32-gcc -V >&5
../glibc-2.12.2/configure: line 2446: i686-pc-mingw32-gcc: command not found
configure:2448: $? = 127
configure:2452: checking for suffix of object files
configure:2478: i686-pc-mingw32-gcc -c conftest.c >&5
../glibc-2.12.2/configure: line 2480: i686-pc-mingw32-gcc: command not found
configure:2482: $? = 127

...which is strange because I can invoke the new compiler from the command line, because it is in the path:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/crossgcc/bin:

These steps I've taken from http://wiki.osdev.org/GCC_Cross-Compiler
Any ideas on how to proceed? Do I need to start hacking my configuration?
Or perhaps I should revert to gcc-4.5.1 and binutils-2-20.1 even though they built and installed correctly?
Looking for a definitive answer. Perhaps someone can comment who has done this successfully?
Thanks for any help.

Re: Cross Compiling for win32

Posted: Sat Jan 01, 2011 6:48 am
by Combuster
It looks like you have overridden gcc with your new crosscompiler. Fix your path variable, check $PREFIX and hope that you didn't overwrite /usr/bin/gcc

Re: Cross Compiling for win32

Posted: Sat Jan 01, 2011 3:06 pm
by Brynet-Inc
Combuster wrote:It looks like you have overridden gcc with your new crosscompiler. Fix your path variable, check $PREFIX and hope that you didn't overwrite /usr/bin/gcc
Hilarious! :lol:

Re: Cross Compiling for win32

Posted: Thu Jan 06, 2011 9:33 pm
by hibbity
To re-cap.
I have verified the steps at http://wiki.osdev.org/GCC_Cross-Compiler up to and including "Summary" and "Usage". However, the next step says, keep your Bash window open and type:

make all-target-libgcc
make install-target-libgcc

If I understand this correctly, running these commands will invoke /usr/bin/gcc instead of the newly created one.
BUT, I find this is not the case...
First, by renaming /usr/bin/gcc to /usr/bin/gcc_ and renaming /usr/bin/g++ to /usr/bin/g++_
Then running "make all-target-libgcc" results in exactly the same compile error as before:

../../../gcc-4.5.2/libgcc/../gcc/config/i386/cygming.h:103:19: fatal error: stdio.h: No such file or directory
compilation terminated.
make[1]: *** [_muldi3.o] Error 1

I have set the environment as:
#!/bin/sh
export TARGET=i686-pc-mingw32
export PREFIX=/usr/local/crossgcc
export TARGET_PREFIX=$PREFIX/$TARGET
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PREFIX/bin:

I observe that /usr/bin/gcc was not overwritten, and both PATH and PREFIX have been verified as correct.

So I say again. Any ideas on how to proceed? Thank you.

Re: Cross Compiling for win32

Posted: Fri Jan 07, 2011 3:43 am
by Solar
hibbity wrote:First, by renaming /usr/bin/gcc to /usr/bin/gcc_ and renaming /usr/bin/g++ to /usr/bin/g++_
The output of

Code: Select all

which gcc
would be interesting at this point.

Re: Cross Compiling for win32

Posted: Mon Jan 17, 2011 10:14 am
by eAlex79
If your new built compiler sits at $PREFIX/$TARGET the adding $PREFIX/bin to path is not right...

libgcc fails to build because your cross compiler has no C library (and so, no headers) available.

glibc has not been ported to Win32/mingw32 so it will fail anyways.

Re: Cross Compiling for win32

Posted: Mon Jan 17, 2011 12:05 pm
by Solar
eAlex79 wrote:If your new built compiler sits at $PREFIX/$TARGET the adding $PREFIX/bin to path is not right...
IIRC, $PREFIX/bin contains $TARGET-gcc, $PREFIX/$TARGET/bin contains gcc. Thus, you want to add $PREFIX/bin to your path, so that "gcc" is your system compiler and $TARGET-gcc your cross-compiler.

Re: Cross Compiling for win32

Posted: Mon Jan 17, 2011 12:51 pm
by eAlex79
How would a native "gcc" end up beeing at $PREFIX/$TARGET? Unless hibbity tries to build a native win32 mingw compiler there. But I don't read him telling that he's doing a real canadian cross anywhere.

And AFAIK the cross compiler build system doesn't install any non prefixed binaries to wherever/bin.

Maybe hibbity should tell us wether he has configured gcc to install at $PREFIX or at $TARGET_PREFIX.

;) Now I'm confused. lol

I'm just playing with mingw sources here too, trying to get a clean 32bit build system for PE executables for a dos extender without mingw's windows stuff.

Re: Cross Compiling for win32

Posted: Mon Jan 17, 2011 9:06 pm
by hibbity
"which gcc" gives: /usr/local/gcc

Running "$PREFIX/bin/i686-pc-mingw32-gcc --version" gives:
i686-pc-mingw32-gcc (GCC) 4.5.2

Running "i686-pc-mingw32-gcc --version" gives the same result, since i686-pc-mingw32-gcc is in the path.

If "i686-pc-mingw32-gcc" can be invoked from the command line, then why can the configure script not find "i686-pc-mingw32-gcc" ?

configure:2414: checking for C compiler version
configure:2422: i686-pc-mingw32-gcc --version >&5
../glibc-2.12.2/configure: line 2424: i686-pc-mingw32-gcc: command not found

Re: Cross Compiling for win32

Posted: Tue Jan 18, 2011 1:15 am
by Solar
Check out the contents of the file config.log. Sometimes the on-screen output of ./configure does not tell the whole story.