views:

1325

answers:

3

Hello,

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.

+1  A: 

I grepped through the MinGW sources, and found that dllcrt2.o is something built off the mingwrt package. I assume you have to compile and install that, not just copy the headers?

DevSolar
Yes, yes.Copying headers is just one from many steps.After the 5th step in my post I should do this:-6. Build "c (only) cross-compiler".-7. Add the location with just compiled binaries to "PATH" environment variable.-8. Build "win32api".-9. Build "mingwrt".-10. Build "c and c++ cross-compiler".But for now I am just at 6th step and getting that error.
Petike
Hmmm... haven't toyed with MinGW myself. But when I set up a first-stage cross-compiler, I use "--without-headers" on the configure line to tell it not to rely on any kind of C library or runtime for the target. I don't know which how-to you are following or how things work with MinGW, but perhaps you give it a shot.
DevSolar
+6  A: 

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.)

FX
Thank you very much for your comment: "You have successfuly performed step 3 above". I thought if I get any error I cannot go to the next step, but (fortunately) I was wrong. Next I successfully compiled win32api, but I got some errors when I tried to compile mingwrt - something was wrong with "threading". So I decided to compile gcc with these parameters: --prefix="${HOME}/gcc" --target=i386-mingw32 --program-prefix=i386-mingw32 --enable-languages=c,c++ --with-headers="${HOME}/gcc/i386-mingw32/include" --disable-nls --disable-threads --disable-shared --disable-libssp.And this worked!!!
Petike
I am sorry for a little mistake from previous comment: the problem was in "shared" option and NOT with "threads" option. So it compiled also without "--disable-threads" specified.
Petike
Regarding threads, you can also build GCC with `--enable-libgomp` (for OpenMP) if you have the pthreads-win32 library installed.
FX
+1  A: 

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://mstenberg.com/blog/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.

mitchy