Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building GCC cross compiler (from "Linux" to "Windows")

I want to build "gcc cross-compiler" to compile "c/c++" applications on "Linux" environment but for "Windows" target.

I have made this so far:

  1. Installed the necessary tools and packages for building GCC listed on "Prerequisites for GCC" page.

  2. Downloaded required sources:
    "gcc-core-4.4.1", "gcc-g++-4.4.1", "binutils-2.19.1", "w32api-3.13-mingw32", "mingwrt-3.16-mingw32"

  3. Created this directory hierarchy:
    "${HOME}/gcc/" - for final cross-compiler
    "${HOME}/src/" - for sources
    "${HOME}/src/build-binutils/i386-mingw32/" - for building binutils to "i386-mingw32" target
    "${HOME}/src/build-gcc/i386-mingw32/" - for building gcc to "i386-mingw32" target

  4. Builded binutils package:

    cd "${HOME}/src/build-binutils/i386-mingw32/"
    ../../binutils-2.19.1/configure --prefix="${HOME}/gcc" --target=i386-mingw32 --disable-nls
    make
    make install

  5. Copied "w32api" and "mingwrt" headers to the install directory:

    cp -R "${HOME}/src/w32api-3.13-mingw32/include" "${HOME}/gcc/i386-mingw32"
    cp -R "${HOME}/src/mingwrt-3.16-mingw32/include" "${HOME}/gcc/i386-mingw32"


And now when I am trying to build the "c (only) cross-compiler":

cd "${HOME}/src/build-gcc/i386-mingw32/"
../../gcc-4.4.1/configure --prefix="${HOME}/gcc" --target=i386-mingw32 --enable-languages=c --with-headers="${HOME}/gcc/i386-mingw32/include" --disable-nls
make<br>

it was building something about 4 minutes and then gives me these errors:

${HOME}/gcc/i386-mingw32/bin/ld: dllcrt2.o: No such file: No such file or directory
collect2: ld returned 1 exit status
make[2]: *** [libgcc_s.dll] Error 1
make[2]: Leaving directory `${HOME}/src/build-gcc/i386-mingw32/i386-mingw32/libgcc'
make[1]: *** [all-target-libgcc] Error 2
make[1]: Leaving directory `${HOME}/src/build-gcc/i386-mingw32'
make: *** [all] Error 2

From that error message I really don't know what to do now :-((( .


Does anybody know where is the problem?
Thanks.

like image 304
Petike Avatar asked Sep 24 '09 23:09

Petike


2 Answers

That's actually OK: the way things go, you need to

  1. build binutils
  2. install headers
  3. build the a partial C compiler: enough to create object files, but not enough to link
  4. build the win32api and mingw runtime (which includes your missing dllcrt2.o)
  5. build a complete C compiler (and other front-ends, such as C++, Fortran, Ada, whatever, if you want them)

You have successful performed step 3 above; it fails building libgcc (which is a GCC support library), but that means the C compiler core is functionnal (although it won't be able to link, it can still create valid object files). You can check that by looking at the gcc/xgcc file in your GCC build directory.

So, you need to go to the next step, not worrying about your current failure.

(To actuall install the partial C compiler, you should run make with the -k option, to have it do it best, even in the face of errors. For example, use make -k install.)

like image 85
F'x Avatar answered Oct 26 '22 23:10

F'x


There are precompiled cross-compilers of MinGW-w64 available. This allows to compile native 32- and 64-bit Windows binaries from Linux, a two minute tutorial is available at http://www.blogcompiler.com/2010/07/11/compile-for-windows-on-linux/

Just in case you don't want to spend a lot of time trying to build it yourself.

like image 35
mitchy Avatar answered Oct 26 '22 22:10

mitchy