簡體   English   中英

g86 i686在x86_64平台上

[英]gcc i686 on x86_64 platform

我在RHEL X86_64上安裝GCC i686有些麻煩。 實際上,我必須在這個平台上構建一些32位軟件和共享庫。 我可以在32位平台(linux或windows)上構建這些軟件和庫。

我的問題在這篇文章的最后。

我的第一個問題是這個錯誤:(在建築期間,在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 include,但是我有很多文件,有時這個技巧無論如何都沒有用。 而且,我不應該修改源文件。

當我使用朋友給出的makefile來構建共享庫時,我遇到了完全相同的問題。 這個makefile在他的平台上運行良好(和我一樣,RHEL 4.4.6 x86_64)。

他告訴我錯誤出現是因為我使用X86_64 lib來構建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 =>好的
  • ' 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,一切正常,但下一個源文件出現錯誤...

沒有必要編譯32位版本的GCC; 只需提供-m32標志即可生成64位版本的GCC( FAQ條目 )的32位代碼。

這個問題支持這個: 如何在x86_64機器上編譯glibc 32bit

請注意,您可能必須安裝32位版本並開發要編譯的代碼的所有依賴項的包(即linux頭文件,glibc,...)

編輯為了調試這樣的問題,查看GCC嘗試編譯的源通常很有用。 為此,請使用gcc -E而不是gcc -c 這將為您提供預處理的C源以及許多#line語句,這些語句告訴GCC正在讀取哪些文件以生成后面的內容。

創建這樣的文件並檢查它。 上面的錯誤讓我想知道你是否創建了一個預處理器宏,它在stdlib.h擴展為意外的東西。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM