title: gcc i686 on x86_64 platform
body: <p>I have some troubles to install GCC i686 on a RHEL X86_64.
  Indeed, I have to build some 32bit softwares and shared libraries on this platform.
  I can build these softwares and libraries on 32bit platforms (linux or windows). </p>
  
  <p>My questions are at the end of this post.</p>
  
  <p>My first problem was this error: (during a buil, under eclipse -helios)</p>
  
  <pre><code>In file included from /usr/include/stdlib.h:314,
                    from ../../../../../XXXX.h:19,
                    from /XXXX.c:33: 
  /usr/include/sys/types.h:150: error: duplicate 'unsigned' 
  /usr/include/sys/types.h:151: error: duplicate 'unsigned' 
  /usr/include/sys/types.h:151: error: duplicate 'short' 
  /usr/include/sys/types.h:152: error: duplicate 'unsigned' 
  /usr/include/sys/types.h:152: error: two or more data types in declaration specifiers 
  make: *** [XXXX.o] Error 1
  </code></pre>
  
  <p>To correct this error, I had to put the stdlib.h include before all the other files, but I have a lot of files, and sometimes this trick did not work anyway.
  Moreover, I should not modify the source files.</p>
  
  <p>I have exactly the same problem when I use a makefile given by a friend, to build a shared library.
  This makefile works well on his platform (the same as me, RHEL 4.4.6 x86_64).</p>
  
  <p>He told me the error appears because I use X86_64 lib, to build a 32bits software (or shared lib).</p>
  
  <p>Here's my version of GCC :</p>
  
  <pre><code>GCC version
  
  [root@localhost bin]# gcc -v
  Target: x86_64-redhat-linux
  Configured with: ../configure --prefix=/usr 
  --mandir=/usr/share/man 
  --infodir=/usr/share/info 
  --with-bugurl=http://bugzilla.redhat.com/bugzilla 
  --enable-bootstrap 
  --enable-shared 
  --enable-threads=posix 
  --enable-checking=release 
  --with-system-zlib 
  --enable-__cxa_atexit 
  --disable-libunwind-exceptions 
  --enable-gnu-unique-object 
  --enable-languages=c,c++,objc,obj-c++,java,fortran,ada 
  --enable-java-awt=gtk 
  --disable-dssi 
  --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre 
  --enable-libgcj-multifile 
  --enable-java-maintainer-mode 
  --with-ecj-jar=/usr/share/java/eclipse-ecj.jar 
  --disable-libjava-multilib 
  --with-ppl 
  --with-cloog 
  --with-tune=generic 
  --with-arch_32=i686 
  --build=x86_64-redhat-linux
  thread: posix
  gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) 
  
  [root@localhost bin]# rpm -qa |grep gcc
  gcc-c++-4.4.6-3.el6.x86_64
  gcc-4.4.6-3.el6.x86_64
  gcc-gfortran-4.4.6-3.el6.x86_64
  </code></pre>
  
  <p>So first, I installed glibc.i686 and libgcc.i686 packages from the RHEL DVD setup.
  Now I have:</p>
  
  <pre><code>Installed packages (from redhat DVD)
  [root@localhost bin]# rpm -qa |grep glibc
  glibc-common-2.12-1.47.el6.x86_64
  glibc-2.12-1.47.el6.x86_64
  glibc-devel-2.12-1.47.el6.x86_64
  glibc-devel-2.12-1.47.el6.i686
  glibc-headers-2.12-1.47.el6.x86_64
  glibc-2.12-1.47.el6.i686
  
  [root@localhost bin]# rpm -qa |grep libgcc
  libgcc-4.4.6-3.el6.x86_64
  libgcc-4.4.6-3.el6.i686
  </code></pre>
  
  <p>Since GCC is x86_64, I read some documents about the cross compilation, espcially this one:
  <a href="http://wiki.osdev.org/GCC_Cross-Compiler" rel="nofollow">wiki.osdev.org/GCC_Criss-Compiler</a> </p>
  
  <p>So I downloaded: gcc-4.4.6.tar.gz, binutils-2.23.tar.gz, gmp-5.0.2.tar.gz, and mpfr-3.1.1.tar.gz.
  I put the directories gmp-5.0.2 and mpfr-3.1.1 in gcc-4.4.6 directory (and I renamed gmp-5.0.2 to gmp, and mpfr-3.1.1 to mpfr). </p>
  
  <p>I followed the wiki.osdev instructions, that is:</p>
  
  <pre><code>export PREFIX=/usr/local/cross
  export TARGET=i686-elf
  cd /usr/src
  mkdir build-binutils build-gcc
  cd /usr/src/build-binutils
  ../binutils-x.xx/configure --target=$TARGET --prefix=$PREFIX --disable-nls
  make all
  make install
  cd /usr/src/build-gcc
  export PATH=$PATH:$PREFIX/bin
  ../gcc-x.x.x/configure --target=$TARGET --prefix=$PREFIX --disable-nls \
      --enable-languages=c,c++ --without-headers
  make all-gcc
  make install-gcc
  </code></pre>
  
  <ul>
  <li>'<strong>make all</strong>' and '<strong>make install</strong>' for binutils => OK</li>
  <li>'<strong>make all-gcc</strong>'</li>
  </ul>
  
  <p>--> 1st error: missing "mpfr.h" in "real.h". So I added mpfr.h in gcc-4.4.6/gcc and it was OK (maybe not actually ...)</p>
  
  <p>--> 2nd error (the only one now):</p>
  
  <pre><code>[...]
  gcc  -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE  -W -Wall 
  -Wwrite-strings 
  -Wstrict-prototypes 
  -Wmissing-prototypes 
  -Wcast-qual 
  -Wold-style-definition 
  -Wc++-compat 
  -Wmissing-format-attribute 
  -pedantic 
  -Wno-long-long 
  -Wno-variadic-macros 
  -Wno-overlength-strings   
  -DHAVE_CONFIG_H  
  -o cc1-dummy c-lang.o stub-objc.o attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o 
  c-typeck.o c-convert.o c-aux-info.o c-common.o c-opts.o c-format.o c-semantics.o 
  c-ppoutput.o c-cppbuiltin.o c-objc-common.o c-dump.o c-pch.o c-parser.o i386-c.o 
  c-gimplify.o tree-mudflap.o c-pretty-print.o c-omp.o dummy-checksum.o \
                main.o  libbackend.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a ../libcpp/libcpp.a   ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a   
  -L/usr/src/build-gcc/./gmp/.libs -L/usr/src/build-gcc/./gmp/_libs 
  -L/usr/src/build-gcc/./mpfr/.libs -L/usr/src/build-gcc/./mpfr/_libs 
  -lmpfr -lgmp
  **/usr/bin/ld: cannot find -lmpfr
  collect2: ld returned 1 exit status
  make[1]: *** [cc1-dummy] Error 1
  make[1]: Leaving directory `/usr/src/build-gcc/gcc'
  make: *** [all-gcc] Error 2**
  </code></pre>
  
  <p>**Finally, my questions are :</p>
  
  <ul>
  <li><p>Is this cross-compilation can resolve my problem ?</p></li>
  <li><p>What is the good way to resolve the problem of the missing ld mpfr ?**</p></li>
  </ul>
  
  <p>I made a lot of research before posting. My linux knowledges are not very good at this time.</p>
  
  <p>Thank you in advance for your help.</p>
  
  <hr>
  
  <p><em><strong></em> EDIT #1 :</strong></p>
  
  <p>I've already tried -m32 flag but the problem still here.</p>
  
  <p>For example, if I run a makefile:</p>
  
  <pre><code>[root@localhost makefile]# make -f sharedLib.mak
  gcc -m32 -march=i686 -O2  -Wall -I ../../sharedLib/inc/ -o XXX.o -c ../src/XXX.c
  In file included from /usr/include/stdlib.h:314,
                   from ../src/XXX.c:51:
  /usr/include/sys/types.h:150: error: duplicate 'unsigned'
  /usr/include/sys/types.h:151: error: duplicate 'unsigned'
  /usr/include/sys/types.h:151: error: duplicate 'short'
  /usr/include/sys/types.h:152: error: duplicate 'unsigned'
  /usr/include/sys/types.h:152: error: two or more data types in declaration specifiers
  make: *** [XXX.o] Error 1
  </code></pre>
  
  <p>Here's XXX.c:</p>
  
  <pre><code>#include "alphabet.h"
  #include "outils.h"
  #include "erreur.h"
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt; (line 51 error)
  </code></pre>
  
  <p>If a modify this way:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include "alphabet.h"
  #include "outils.h"
  #include "erreur.h"
  #include &lt;string.h&gt;
  </code></pre>
  
  <p>Everything is OK for XXX.c but the error appears for the next source file ...</p>