2

I'm trying to make a cross compiler with the files from http://crossgcc.rts-software.org/doku.php?id=i386linuxgccformac

I'm on an Intel Mac (10.6.6, x86_64) I compiled: gmp, mpfr, mpc for the cross compiler as 32bit (as I'm on a 64bit Mac) but I'm getting

ld: warning: option -s is obsolete and being ignored
ld: warning: ignoring file /gmp1/lib/libmpc.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /gmp1/lib/libmpfr.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /gmp1/lib/libgmp.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

When compiling GCC with:

--prefix=/usr/local/i386-linux-4.5.2 --target=i386-linux --enable-languages=c --without-headers --disable-shared --disable-threads --disable-nls --with-gmp=/gmp1 --with-gmp-lib=/gmp1 --with-gmp-include=/gmp1 --with-mpfr=/gmp1 --with-mpfr-include=/gmp1 --with-mpfr-lib=/gmp1 --with-mpc=/gmp1 --with-mpc-lib=/gmp1 --with-mpc-include=/gmp1

Also, if I compile GMP with:

./configure --prefix=/gmp1 --host=i386-linux

I get:

configure: WARNING: +----------------------------------------------------------
configure: WARNING: | Cannot determine global symbol prefix.
configure: WARNING: | link -dump -symbols output doesn't contain a global data symbol.
configure: WARNING: | Will proceed with no underscore.
configure: WARNING: | If this is wrong then you'll get link errors referring
configure: WARNING: | to ___gmpn_add_n (note three underscores).
configure: WARNING: | In this case do a fresh build with an override,
configure: WARNING: |     ./configure gmp_cv_asm_underscore=yes
configure: WARNING: +----------------------------------------------------------
checking how to switch to read-only data section... .data
checking for assembler .type directive... 
checking for assembler .size directive... 
checking for assembler local label prefix... configure: WARNING: "link -dump -symbols" failure
configure: WARNING: cannot determine local label, using default L
L
checking for assembler byte directive... .byte
checking how to define a 32-bit word... link: illegal option -- d
Mat
  • 202,337
  • 40
  • 393
  • 406
Daniel
  • 3,017
  • 12
  • 44
  • 61

2 Answers2

6

I think that you are confused about which package should be compiled for which platform:

  • GCC needs to be compiled for an x86_64 MacOS X host and an i386-linux target.

  • GMP, MPC and MPFR are runtime dependencies for GCC. Therefore they also need to be compiled for the GCC host - x86_64 in your case. Therefore, the --host=i386-linux option in the GMP configure command is incorrect.

In general, only libraries that will be linked in the programs compiled by GCC need to be built for the cross-compiler target (e.g. i386-linux). GMP and MPFR are not such libraries, unless your programs are actually using them - in that case you will need to have two copies of such libraries, one for GCC and a cross-build for the target.

EDIT:

Have you considered using MacPorts? It has all the dependencies for your cross-compiler:

There is also an older newlib-based cross-compiler for i386:

Even if you do not want to use these, you can still have a look at the build instructions in their Portfiles.

The bottom line is:

  • Apply whatever patches these libraries need - MacPorts already do that.

  • Compile the libraries for your build host i.e. MacOSX/x86_64. That means that in any --host options for their configure calls you should be something along the lines of --host=x86_64-darwin (or whatever your host needs). If configure can figure out the host on its own, you can skip the --host options altogether.

  • Compile GCC with --host being your build host (the 64-bit Mac OS X) and a target of i386-linux, e.g. --target=i386-linux. If I were you, I'd start simple with a compiler for the C and C++ languages only.

See also this tutorial. It has some information on how to produce a working toolchain with a proper glibc.

That said, I think that you'd be better off installing a proper Linux distribution in a virtual machine, for a whole bunch of reasons. Is there a reason for you to need a cross-compiler specifically? What do you want to do with that compiler?

thkala
  • 84,049
  • 23
  • 157
  • 201
  • I'm a bit confused, could you please give an example – Daniel Mar 09 '11 at 12:13
  • @thkala also gmp doesn't allow --target to be set? – Daniel Mar 09 '11 at 12:15
  • @thkala i tried "./configure --prefix=/gmp1 --host=i386-apple-darwin10.6.0 --build=i386-linux --with-gmp=/gmp1 --with-mpfr=/gmp1" but it comes up with the above error (as mentioned in the question) – Daniel Mar 09 '11 at 12:21
  • @Daniel: gmp, mpfr and mpc need to be compiled for your build host - just compile them as you would any other library for Darwin. `--target` has no meaning for them. Only GCC has a target option. – thkala Mar 09 '11 at 12:38
  • i'm confused still, i tried ./configure --prefix=/gmp1 before and it comes up with "/gmp1/lib/lib.gmp.dylib, file was built for unsupported file format which is not the architecture being linked (i386) " – Daniel Mar 09 '11 at 12:44
  • Maybe i didn't explain it properly, i'm building gmp, mpfr and mpc for my current gcc so i can compile a cross compiler using it – Daniel Mar 09 '11 at 12:56
  • @Daniel: can you try something? Compile mpfr, gmp, mpc and gcc with no `--host` options at all, just `--target` for GCC. Let `configure` try to figure it out... – thkala Mar 09 '11 at 13:34
  • I'm compiling gmp seperate from gcc? – Daniel Mar 10 '11 at 10:38
  • @Daniel: GCC uses the system-wide GMP, MPC and MPFR, just like any other program running on the build host. As such, the compilation of these packages is independent of GCC. – thkala Mar 10 '11 at 19:58
  • @thkala Well its compiled and installed but how come i get the above error? – Daniel Mar 10 '11 at 22:34
  • @Daniel: Could you be more specific on how you compiled what and the error that you are getting? Just to make sure that we're on the same page before I start offering suggestions... – thkala Mar 10 '11 at 23:47
  • @thkala I'm trying to compile gmp, mpfr, mpc for my current gcc compiler (which came with xcode) which is x86_64 on an intel mac 10.6.6 so i can use that to compile another gcc compiler for i386-linux. what ./configure command should i use for gmp, mpfr and mpc? – Daniel Mar 11 '11 at 03:37
  • @Daniel: you should compile those libraries with the correct options for using them on your build host (i.e. on your Mac). You may want to add `--prefix`, so that they do not mess with the system-wide versions, but I think `configure` should be able to figure out the rest. I'd start with `./configure --prefix=/test` or something. Make sure to add the correct `--with-xxx=...` options for any library you install in a non-standard directory. – thkala Mar 11 '11 at 10:04
  • @thkala i still have not got this to work. and the bounty of 50 is ending very soon. please help – Daniel Mar 12 '11 at 06:47
  • @thkala regarding the update to your answer, i'm need to use a cross compiler simply because its too much of a hassle to switch between a VM and mac os x, i'm not 100% sure what the problem is why its saying no symbols – Daniel Mar 12 '11 at 21:05
  • @thkala The problem is that the gmp, mpfr and mpc install on my mac is built for x86_64 darwin (which is fine for native compiling) but i don't know what to do to get gmp installed so gcc can compile the cross compiler linked with the gmp,mpfr, mpc libraries. I've set the --with-gmp but it doesn't seam to make much difference – Daniel Mar 12 '11 at 21:08
  • @thkala ok sorry for the responses, i tried compiled gmp with ./configure --prefix=/gmp1 --host=i386-linux --build=x86_64-darwin10.6.0 but at the end of the compile process it comes with tons of "has no symbols": /usr/bin/ranlib: file: .libs/libgmp.a(mp_clz_tab.o) has no symbols /usr/bin/ranlib: file: .libs/libgmp.a(obprintf.o) has no symbols /usr/bin/ranlib: file: .libs/libgmp.a(obvprintf.o) has no symbols /usr/bin/ranlib: file: .libs/libgmp.a(obprntffuns.o) has no symbols – Daniel Mar 12 '11 at 21:18
  • @thkala "make check" comes up with Undefined symbols for architecture i386 just the same as gcc did?? – Daniel Mar 12 '11 at 21:22
  • @Daniel: GCC uses gmp etc for static arithmetic expression evaluation. As such, the native version is fine for a crosscompiler too. IIRC only the Fortran backend needs a version of those libraries suitable for the target - unless that has changed in recent versions. Have you tried building a C-only cross-compiler? – thkala Mar 12 '11 at 21:23
  • the cross compiler its building is C only – Daniel Mar 12 '11 at 21:26
  • @Daniel: err... `--host=i386-linux` does not sound right. The cross compiler itself should be using libraries native to the build host (the Mac). Only any stubs/shared libs linked in the compiled programs should use libraries native to the target (i386). – thkala Mar 12 '11 at 21:27
  • Ok well, how about if i recompile gmp without any --host, --build options, should it make any difference if the cross compiler is going to be made as 32bit but gmp is compiled as 64bit? – Daniel Mar 12 '11 at 21:29
  • @Daniel: The cross compiler executables should be 64-bit. The binaries is produces should be 32-bit. – thkala Mar 12 '11 at 22:03
  • @thkala how about i send you the config.log? – Daniel Mar 12 '11 at 22:10
  • @Daniel: I just built a naked (i.e. without glibc) C/C++ cross-compiler for arm-linux-elf. The only GMP, MPC and MPFR it needs are the ones that come with my linux distribution, yet it produces object files for ARM with no problem. Have you gotten to this stage? – thkala Mar 13 '11 at 00:53
  • i think theres a problem with mac os x's C libraries, gmp doesn't even compile properly (says no symbols) without or with --build --host – Daniel Mar 13 '11 at 02:30
  • @Daniel: have you tried getting GMP etc from MacPorts? IIRC there were a few patches included... – thkala Mar 13 '11 at 02:32
  • sudo port install gmp-5.0.1 Password: Error: Port gmp-5.0.1 not found – Daniel Mar 13 '11 at 02:34
  • How did you build your "naked (without glibc) cross compiler"? – Daniel Mar 13 '11 at 02:36
  • @Daniel: uhh... I think it should be `sudo port install gmp` – thkala Mar 13 '11 at 02:41
  • sudo port install gmp comes up with: ---> Cleaning gmp and exits – Daniel Mar 13 '11 at 02:42
  • The following ports are currently installed: gmp @5.0.1_0 (active) platform='darwin 10' archs='x86_64' – Daniel Mar 13 '11 at 02:48
  • @Daniel: now install mpfr and libmpc - then you can try building your cross compiler. – thkala Mar 13 '11 at 02:49
  • installed that but same problem? also sorry about the 50 rep not being awarded to you, i had to go out before it expired – Daniel Mar 13 '11 at 07:09
  • @Daniel: Hmm.. same problem? Strange... did you, by any chance, specify a `--with-gmp=` option? If you did, try removing it - GCC's configure might be able to find gmp on its own now... – thkala Mar 13 '11 at 10:12
  • @thkala is there some way we can talk on a live chat or something, its pretty hard to explain like this – Daniel Mar 13 '11 at 11:52
  • I just tried compiling gcc with: ../gcc-4.5.2/configure --enable-languages=c --without-headers --disable-shared --disable-threads --disable-nls --target=i386-linux --prefix=/usr/local/i386-linux-4.5.2 and i get: ../../../gcc-4.5.2/libgcc/config/libbid/bid_decimal_globals.c:47:18: fatal error: fenv.h: No such file or directory compilation terminated. make[2]: *** [bid_decimal_globals.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [all-target-libgcc] Error 2 make: *** [all] Error 2 – Daniel Mar 13 '11 at 12:00
  • @Daniel: I was unable to compile libgcc for ARM with a "naked" compiler - perhaps you need a libc for that. I just built the cross-compiler with `make all-gcc` and then `make install-gcc`. – thkala Mar 13 '11 at 12:36
  • is there some way we can talk on a live chat or something, its pretty hard to explain like this – Daniel Mar 13 '11 at 12:37
  • @Daniel: I would rather keep the complete discussion here - that way anyone else having this issue will not miss out on any information. You can edit your question with any additional information - this has the added advantage of updating its status in SO which might get someone else to answer, as well. – thkala Mar 13 '11 at 13:43
  • @Daniel: Have you tried compiling gcc with `configure --disable-nls --enable-languages=c,c++ --without-headers --target=i386-linux-elf --prefix=/usr/local/i386-linux-4.5.2` and then `make all-gcc` ? – thkala Mar 14 '11 at 01:52
  • i tried it just now, i think it worked :) but i'll have to double check – Daniel Mar 14 '11 at 02:08
  • @Daniel: if `make all-gcc` succeeded, you can install with `make install-gcc`. To test your compiler you may have to modify the PATH variable so that `as` and the other binutils for i386-linux will come before the system-wide `as` when running the cross-compiler. – thkala Mar 14 '11 at 02:15
  • @Daniel: Also keep in mind that you cannot link a program for Linux with this compiler. You can only create object files (the `-c` flag) and you can only link executables that do not require runtime objects. You need a libc and a second cross-compiler for that. Essentially you may be able to cross-compile a Linux kernel, but you cannot (yet) cross compile "Hello world"... – thkala Mar 14 '11 at 02:17
  • Ok, i think i'm going to just forget about making a cross compiler on my mac for linux, its too much of a hassle, could you help me make a cross compiler for arm-linux on a linux virtual machine? – Daniel Mar 14 '11 at 02:30
0

Did you use the "ABI=32" option when compiling GMP? If not, I think it will use 64-bit code even if the host/target are specified as i386.

casevh
  • 11,093
  • 1
  • 24
  • 35