2016-03-03 119 views
1

我試圖構建gcc-5.3和binutils-2.26。我這樣做了:GCC&binutils構建 - C編譯器無法創建可執行文件

mkdir gcc; cd gcc 
wget http://path/to/gcc-5.3.0.tar.bz2 
wget http://path/to/binutils-2.26.tar.bz2 
tar xf gcc-5.3.0.tar.bz2 
tar xf binutils-2.26.tar.bz2 
cd gcc-5.3.0 
contrib/download_prerequisites 
for file in ../binutils-2.26/*; do ln -s "${file}"; done 
cd .. 
mkdir build 
mkdir dist 
cd build 
../gcc-5.3.0/configure --prefix=/home/teamcity/gcc/dist --disable-multilib --with-system-zlib --enable-languages=c,c++,fortran --program-suffix=-mine 
make 

這似乎是構建第一階段的可執行文件好嗎; prev-gas,prev-gcc,prev-ld都與他們看起來似乎合理的可執行文件。但下一階段失敗:

Configuring stage 2 in ./intl 
configure: loading cache ./config.cache 
checking whether make sets $(MAKE)... yes 
checking for a BSD-compatible install... /usr/bin/install -c 
checking whether NLS is requested... yes 
checking for msgfmt... /usr/bin/msgfmt 
checking for gmsgfmt... /usr/bin/msgfmt 
checking for xgettext... /usr/bin/xgettext 
checking for msgmerge... /usr/bin/msgmerge 
checking for x86_64-unknown-linux-gnu-gcc... /home/teamcity/gcc/build/./prev-gcc/xgcc -B/home/teamcity/gcc/build/./prev-gcc/ -B/home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/bin/ -B/home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/bin/ -B/home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/lib/ -isystem /home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/include -isystem /home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/sys-include -L/home/teamcity/gcc/build/./ld 
checking for C compiler default output file name... 
configure: error: in `/home/teamcity/gcc/build/intl': 
configure: error: C compiler cannot create executables 
See `config.log' for more details. 

的config.log的相關位似乎是這樣的:

configure:2978: checking for C compiler default output file name 
configure:3000: /home/teamcity/gcc/build/./prev-gcc/xgcc -B/home/teamcity/gcc/build/./prev-gcc/ -B/home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/bin/ -B/home/teamcity/gcc/dist/x86_64-unkn 
own-linux-gnu/bin/ -B/home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/lib/ -isystem /home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/include -isystem /home/teamcity/gcc/dist/x86_64-unknown-l 
inux-gnu/sys-include -L/home/teamcity/gcc/build/./ld -g -O2 -gtoggle -static-libstdc++ -static-libgcc conftest.c >&5 
/home/teamcity/gcc/build/./prev-gcc/as: 106: exec: /home/teamcity/gcc/build/./gas/as-new: not found 

這看起來像上一個-gcc的如希望找到gas/as-new,而實際上它是prev-gas/as-new

有沒有一些解決方法呢?是否安全到ln -s prev-gas gas?我有點期待以後會引起問題。難道不可能一起構建這兩個版本的gcc和binutils嗎?

+0

錯字: wget http://path/to/binutils-5.3.0.tar.bz2應該在路徑中可能有2.26而不是5.3.0? –

+0

完全正確。我會解決它。 – Tom

+0

還應該提到構建平臺是Ubuntu 14.04,使用與系統安裝的GCC 4.8。 – Tom

回答

0

這是我自己在Ubuntu 14.04 Azure虛擬機上嘗試它後編輯的答案。

以下辦法爲我工作:

  • 構建和安裝的binutils 2.26;爲了討論的目的,我們假設它被安裝在/opt/gcc-5.3.0中。
  • 假設gcc-5.3.0和生成目錄objdir處於相同的 級別,在構建目錄中使用/root/objdir/../gcc-5.3.0/configure --prefix=/opt/gcc-5.3.0 --enable-languages=c,c++ --disable-multilib --with-ld=/opt/gcc-5.3.0/bin/ld --with-as=/opt/gcc-5.3.0/bin/as配置gcc-5.3.0。
  • makemake installobjdir建立目錄。

爲了驗證由新建成gcc使用的ld是一個來自新的binutils:

/opt/gcc-5.3.0/bin/gcc -print-prog-name=ld 

輸出應,在本實施例中:

/opt/gcc-5.3.0/bin/ld 

另一個測試:重命名系統ld,在我的情況下爲/usr/bin/ld;新建的gcc仍然可以工作。

當然,這適用於ldas

將AS和LD環境變量設置爲指向binutils包中新建的二進制文件不起作用:-print-prog-name=...仍顯示默認工具,並且刪除/重命名默認工具會導致gcc失敗。

因此,完成此操作的最佳方法是首先構建binutils,然後使用--with-ld--with-as選項至configure。如果您還想確保使用新建的binutils來構建GCC,則可能需要在系統提供的工具之前將它們放入PATH中,或者甚至可以重命名系統提供的工具以使其不在圖片。

感謝您使用另一個郵件列表來驗證構建GCC和binutils一起工作,除非它們從源代碼管理控件中被取消,我猜這個選項在使用下載的tarball時不適用。總的來說這是一個有趣的練習。

+0

我試過這個。但是,然後建立的GCC最終使用系統ld,而不是binutils 2.26中的那個。 – Tom

+0

我現在看到。我發現了一些與您所描述的相似的說明,但這些說明都是6-7歲,可能已經發生了變化。當我找到時間時,我會在Ubuntu 14.04上玩它,看起來像一個有趣的問題。 – OmniProg

+0

我已經通過構建binutils,安裝,然後使用'AS =/path/to/as-mine'和'LD =/path/to/ld-mine'配置gcc來完成它的工作。我讀過,你也可以使用'--with-as = ...'和'--with-ld = ...'作爲配置選項,但還沒有嘗試過。 – Tom

相關問題