我有些困难在RHEL X86_64上安装GCC i686。实际上,我必须在此平台上构建一些32位软件和共享库。我可以在32位平台(Linux或Windows)上构建这些软件和库。
我的问题在本文末尾。
我的第一个问题是这个错误:(在Eclipse-Helios下进行构建期间)
为了纠正这个错误,我不得不把stdlib.h包含在所有其他文件之前,但我有很多文件,有时这个技巧仍然不起作用。此外,我不应该修改源文件。
当我使用朋友提供的Makefile构建共享库时,我遇到了完全相同的问题。 这个Makefile在他的平台上运行良好(与我相同,RHEL 4.4.6 x86_64)。
他告诉我出现错误是因为我使用X86_64库来构建32位软件(或共享库)。
以下是我的GCC版本:
这是XXX.c文件的内容:
如果我这样修改:
我的问题在本文末尾。
我的第一个问题是这个错误:(在Eclipse-Helios下进行构建期间)
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
为了纠正这个错误,我不得不把stdlib.h包含在所有其他文件之前,但我有很多文件,有时这个技巧仍然不起作用。此外,我不应该修改源文件。
当我使用朋友提供的Makefile构建共享库时,我遇到了完全相同的问题。 这个Makefile在他的平台上运行良好(与我相同,RHEL 4.4.6 x86_64)。
他告诉我出现错误是因为我使用X86_64库来构建32位软件(或共享库)。
以下是我的GCC版本:
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
首先,我从RHEL DVD安装了glibc.i686和libgcc.i686软件包。现在我有以下文件:
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
由于GCC是x86_64, 我阅读了一些关于交叉编译的文档,尤其是这篇文章:wiki.osdev.org/GCC_Criss-Compiler
所以我下载了:gcc-4.4.6.tar.gz, binutils-2.23.tar.gz, gmp-5.0.2.tar.gz和mpfr-3.1.1.tar.gz。我把gmp-5.0.2目录和mpfr-3.1.1目录放在gcc-4.4.6目录中(并将gmp-5.0.2重命名为gmp,将mpfr-3.1.1重命名为mpfr)。
我按照wiki.osdev的说明操作:
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
- 'make all' 和 'make install' 用于 binutils => OK
- 'make all-gcc'
--> 第一个错误:在“real.h”中缺少“mpfr.h”。所以我在gcc-4.4.6/gcc中添加了mpfr.h,然后它就可以了(也许实际上并不是这样)。
--> 第二个错误(现在唯一的错误):
[...]
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**
最后,我的问题是:
这个交叉编译可以解决我的问题吗?
如何解决缺少ld mpfr的问题?
在发布之前,我进行了很多研究。目前为止我的Linux知识不是很好。
谢谢你的帮助。
编辑 #1 :
我已经尝试过-m32标志,但问题仍然存在。
例如,如果我运行一个makefile:
[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
这是XXX.c文件的内容:
#include "alphabet.h"
#include "outils.h"
#include "erreur.h"
#include <string.h>
#include <stdlib.h> (line 51 error)
如果我这样修改:
#include <stdlib.h>
#include "alphabet.h"
#include "outils.h"
#include "erreur.h"
#include <string.h>
对于XXX.c,一切正常,但下一个源文件出现了错误...
-E
运行时,代码不会被编译。你只能使用输出来理解为什么它无法编译!生成的 myLib.a 可能是无用的。 - Aaron Digulla