LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Building a cross-compiler for windows on linux (http://www.linuxquestions.org/questions/programming-9/building-a-cross-compiler-for-windows-on-linux-924524/)

Refractor 01-18-2012 10:49 PM

Building a cross-compiler for windows on linux
 
Greetings,
I need to develop apps for linux and windows, but I prefer building them only my linux box, because 1) It's my main OS, 2) It's faster 3) I don't want to reboot every time I want to rebuild.
I've seen lots of (very old) tutorials on how to set up a cross compiler, but I can't manage to get the resulting cross-compiler to work.

Here's how far I've went:
Packages:
Code:

binutils-2.22
gcc-core-4.6.2
mingwrt-3.20 (from cvs)
w32api-3.17 (from cvs)

Variables:
Code:

$PREFIX=$HOME/w32
$TARGET=i686-pc-mingw32

--
binutils builds fine with
Code:

../configure --prefix=$PREFIX --target=$TARGET && make && make install
copy all the headers from mingw runtime and win32 api:
Code:

cp -Rv mingwrt/include $PREFIX; cp -Rv w32api/include $PREFIX
Next up is gcc:
Code:

../configure --prefix=$PREFIX --target=$TARGET --disable-nls --disable-threads --enable-languages=c && make all-gcc && make install-gcc
Everything works fine:
Code:

axtroz ~/source/win32/w32api/build $ cd $PREFIX
axtroz ~/w32 $ i686-pc-mingw32-ld -V
GNU ld (GNU Binutils) 2.22
  Supported emulations:
  i386pe
axtroz ~/w32 $ i686-pc-mingw32-gcc -dumpmachine
i686-pc-mingw32
axtroz ~/w32 $ i686-pc-mingw32-gcc -v
Using built-in specs.
COLLECT_GCC=i686-pc-mingw32-gcc
COLLECT_LTO_WRAPPER=/home/axtroz/w32/libexec/gcc/i686-pc-mingw32/4.6.2/lto-wrapper
Target: i686-pc-mingw32
Configured with: ../configure --prefix=/home/axtroz/w32 --target=i686-pc-mingw32 --disable-threads --disable-nls --enable-languages=c
Thread model: single
gcc version 4.6.2 (GCC)
axtroz ~/w32 $

The problem is here:

Code:

axtroz ~/w32 $ cat >> hello.c << EOF
> #include <stdio.h>
> int main() {
> printf("Hello, World!\n");
> return 0;
> }
> EOF
axtroz ~/w32 $ i686-pc-mingw32-gc
i686-pc-mingw32-gcc        i686-pc-mingw32-gcc-4.6.2  i686-pc-mingw32-gcov     
axtroz ~/w32 $ i686-pc-mingw32-gcc hello.c -o hello -Wall
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find crt2.o: No such file or directory
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find crtbegin.o: No such file or directory
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lmingw32
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lgcc_eh
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lgcc
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lmoldname
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lmingwex
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lmsvcrt
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lmingw32
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lgcc_eh
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lgcc
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lmoldname
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lmingwex
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lmsvcrt
/home/axtroz/w32/lib/gcc/i686-pc-mingw32/4.6.2/../../../../i686-pc-mingw32/bin/ld: cannot find crtend.o: No such file or directory
collect2: ld returned 1 exit status
axtroz ~/w32 $

I've looked everywhere for at least 1 of the required libraries, but none were found. I've encountered these errors while trying to build the mingwrt, but then even a simple helloworld couldn't build. Help!

Thor_2.0 01-20-2012 08:28 AM

...of course, there is a far easier way, use Java. That IS cross platform...

But, I am a Java affectionado/progger...

Maybe an easier approach? Dunnow.

Thor

Refractor 01-20-2012 12:44 PM

Thank you for the suggestion, though I finally managed to build my cross compiler successfully.
I used as examples the arch PKGBUILD scripts from this post with a few modifications: https://bbs.archlinux.org/viewtopic....988450#p988450

Thor_2.0 01-20-2012 01:28 PM

Thanks for sharing!

Sergei Steshenko 01-21-2012 07:28 AM

Quote:

Originally Posted by Refractor (Post 4579968)
Thank you for the suggestion, though I finally managed to build my cross compiler successfully.
I used as examples the arch PKGBUILD scripts from this post with a few modifications: https://bbs.archlinux.org/viewtopic....988450#p988450

There is a well established piece: http://mingw-cross-env.nongnu.org/ - worked quite well when I tried it a couple of years ago.


All times are GMT -5. The time now is 11:54 PM.