Cross Compiling for win32
Cross Compiling for win32
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.
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.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Re: Cross Compiling for win32
So wait, you want to compile a cross compiler on Ubuntu that runs on Windows but generates ELF executables?
- xenos
- Member
- Posts: 1118
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: Cross Compiling for win32
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.
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
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.
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.
Every good solution is obvious once you've found it.
Re: Cross Compiling for win32
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.
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
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 $? = 127
configure i686-pc-mingw32-gcc -v >&5
../glibc-2.12.2/configure: line 2435: i686-pc-mingw32-gcc: command not found
configure $? = 127
configure i686-pc-mingw32-gcc -V >&5
../glibc-2.12.2/configure: line 2446: i686-pc-mingw32-gcc: command not found
configure $? = 127
configure checking for suffix of object files
configure i686-pc-mingw32-gcc -c conftest.c >&5
../glibc-2.12.2/configure: line 2480: i686-pc-mingw32-gcc: command not found
configure $? = 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.
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 $? = 127
configure i686-pc-mingw32-gcc -v >&5
../glibc-2.12.2/configure: line 2435: i686-pc-mingw32-gcc: command not found
configure $? = 127
configure i686-pc-mingw32-gcc -V >&5
../glibc-2.12.2/configure: line 2446: i686-pc-mingw32-gcc: command not found
configure $? = 127
configure checking for suffix of object files
configure i686-pc-mingw32-gcc -c conftest.c >&5
../glibc-2.12.2/configure: line 2480: i686-pc-mingw32-gcc: command not found
configure $? = 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.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Cross Compiling for win32
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
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Re: Cross Compiling for win32
Hilarious!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
Re: Cross Compiling for win32
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.
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
The output ofhibbity wrote:First, by renaming /usr/bin/gcc to /usr/bin/gcc_ and renaming /usr/bin/g++ to /usr/bin/g++_
Code: Select all
which gcc
Every good solution is obvious once you've found it.
Re: Cross Compiling for win32
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.
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
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.eAlex79 wrote:If your new built compiler sits at $PREFIX/$TARGET the adding $PREFIX/bin to path is not right...
Every good solution is obvious once you've found it.
Re: Cross Compiling for win32
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.
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
"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 checking for C compiler version
configure i686-pc-mingw32-gcc --version >&5
../glibc-2.12.2/configure: line 2424: i686-pc-mingw32-gcc: command not found
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 checking for C compiler version
configure 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
Check out the contents of the file config.log. Sometimes the on-screen output of ./configure does not tell the whole story.
Every good solution is obvious once you've found it.