樹心幽徑

« 20190116在ubuntu 1604裝gcc7及gcc8成功 | Main | 20190117在ubuntu1604裝nfsserver成功 »

20190117在fedora裝gcc7.4成功
2019/01/17,11:54

 

REF:https://gcc.gnu.org/install/configure.html

ref: https://gcc.gnu.org/wiki/InstallingGCC

(1)察看既有版本:

# gcc -v
使用內建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i686-redhat-linux/4.8.3/lto-wrapper
目的:i686-redhat-linux
配置為:../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-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --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-isl=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-i686-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-i686-redhat-linux/cloog-install --with-tune=generic --with-arch=i686 --build=i686-redhat-linux
執行緒模型:posix
gcc version 4.8.3 20140911 (Red Hat 4.8.3-7) (GCC)

(2)# uname -a
Linux localhost.localdomain 3.19.8 #1 SMP Fri Jan 8 12:41:11 CST 2016 i686 i686 i386 GNU/Linux

 

(3)自mirror站下載gcc-7.4 tarball

# wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-7.4.0/gcc-7.4.0.tar.gz

:

2019-01-17 19:55:12 (667 KB/s) - ‘gcc-7.4.0.tar.gz’ saved [112420370/112420370]

 

(4)解開# tar xvzf gcc-7.4.0.tar.gz

 

(5)安裝說明網頁:http://gcc.gnu.org/install/


(6)# pwd
/root/gcc-7.4.0


[root@localhost gcc-7.4.0]# ./contrib/download_prerequisites
2019-01-17 23:26:23 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2019-01-17 23:26:27 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
2019-01-17 23:26:31 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925] -> "./mpc-1.0.3.tar.gz" [1]
2019-01-17 23:26:36 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2 [1626446] -> "./isl-0.16.1.tar.bz2" [1]
gmp-6.1.0.tar.bz2: 正確
mpfr-3.1.4.tar.bz2: 正確
mpc-1.0.3.tar.gz: 正確
isl-0.16.1.tar.bz2: 正確
All prerequisites downloaded successfully.
[root@localhost gcc-7.4.0]#

(7)

# cd ..

# mkdir gcc7obj

# cd gcc7obj/
# ../gcc-7.4.0/configure --prefix=$HOME/GCC-7.4.0 --enable-languages=c,c++,fortran,go

(8)# make

要編譯很久…

:

  done; \
fi
make[5]: Leaving directory `/root/gcc7obj/i686-pc-linux-gnu/libitm'
make[4]: Leaving directory `/root/gcc7obj/i686-pc-linux-gnu/libitm'
make[3]: Leaving directory `/root/gcc7obj/i686-pc-linux-gnu/libitm'
make[2]: Leaving directory `/root/gcc7obj/i686-pc-linux-gnu/libitm'
make[1]: Leaving directory `/root/gcc7obj'
[root@localhost gcc7obj]# date
五  1月 18 15:22:40 CST 2019

(9)# make install

 

:

ldconfig: /root/GCC-7.4.0/lib/libstdc++.so.6.0.24-gdb.py is not an ELF file - it has the wrong magic bytes at the start.

----------------------------------------------------------------------
Libraries have been installed in:
   /root/GCC-7.4.0/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
 /usr/bin/mkdir -p '/root/GCC-7.4.0/share/info'
 /usr/bin/install -c -m 644 ../../../gcc-7.4.0/libitm/libitm.info '/root/GCC-7.4.0/share/info'
 install-info --info-dir='/root/GCC-7.4.0/share/info' '/root/GCC-7.4.0/share/info/libitm.info'
make[4]: Leaving directory `/root/gcc7obj/i686-pc-linux-gnu/libitm'
make[3]: Leaving directory `/root/gcc7obj/i686-pc-linux-gnu/libitm'
make[2]: Leaving directory `/root/gcc7obj/i686-pc-linux-gnu/libitm'
make[1]: Leaving directory `/root/gcc7obj'

(10)

[root@localhost bin]# pwd
/root/GCC-7.4.0/bin

# ls /root/GCC-7.4.0/bin -l
總計 59452
-rwxr-xr-x 4 root root 4101903  1月 18 15:24 c++
-rwxr-xr-x 1 root root 4100493  1月 18 15:24 cpp
-rwxr-xr-x 4 root root 4101903  1月 18 15:24 g++
-rwxr-xr-x 3 root root 4094153  1月 18 15:24 gcc
-rwxr-xr-x 2 root root  121120  1月 18 15:24 gcc-ar
-rwxr-xr-x 2 root root 4102952  1月 18 15:24 gccgo
-rwxr-xr-x 2 root root  121072  1月 18 15:24 gcc-nm
-rwxr-xr-x 2 root root  121084  1月 18 15:24 gcc-ranlib
-rwxr-xr-x 1 root root 3534906  1月 18 15:24 gcov
-rwxr-xr-x 1 root root 2636230  1月 18 15:24 gcov-dump
-rwxr-xr-x 1 root root 2841034  1月 18 15:24 gcov-tool
-rwxr-xr-x 2 root root 4103291  1月 18 15:24 gfortran
-rwxr-xr-x 1 root root 1584406  1月 18 15:24 go
-rwxr-xr-x 1 root root  311119  1月 18 15:24 gofmt
-rwxr-xr-x 4 root root 4101903  1月 18 15:24 i686-pc-linux-gnu-c++
-rwxr-xr-x 4 root root 4101903  1月 18 15:24 i686-pc-linux-gnu-g++
-rwxr-xr-x 3 root root 4094153  1月 18 15:24 i686-pc-linux-gnu-gcc
-rwxr-xr-x 3 root root 4094153  1月 18 15:24 i686-pc-linux-gnu-gcc-7.4.0
-rwxr-xr-x 2 root root  121120  1月 18 15:24 i686-pc-linux-gnu-gcc-ar
-rwxr-xr-x 2 root root 4102952  1月 18 15:24 i686-pc-linux-gnu-gccgo
-rwxr-xr-x 2 root root  121072  1月 18 15:24 i686-pc-linux-gnu-gcc-nm
-rwxr-xr-x 2 root root  121084  1月 18 15:24 i686-pc-linux-gnu-gcc-ranlib
-rwxr-xr-x 2 root root 4103291  1月 18 15:24 i686-pc-linux-gnu-gfortran
[root@localhost bin]#

 

# ./g++ -v
使用內建 specs。
COLLECT_GCC=./g++
COLLECT_LTO_WRAPPER=/root/GCC-7.4.0/libexec/gcc/i686-pc-linux-gnu/7.4.0/lto-wrapper
目的:i686-pc-linux-gnu
配置為:../gcc-7.4.0/configure --prefix=/root/GCC-7.4.0 --enable-languages=c,c++,fortran,go
執行緒模型:posix
gcc version 7.4.0 (GCC)

 

# ./gcc -v
使用內建 specs。
COLLECT_GCC=./gcc
COLLECT_LTO_WRAPPER=/root/GCC-7.4.0/libexec/gcc/i686-pc-linux-gnu/7.4.0/lto-wrapper
目的:i686-pc-linux-gnu
配置為:../gcc-7.4.0/configure --prefix=/root/GCC-7.4.0 --enable-languages=c,c++,fortran,go
執行緒模型:posix
gcc version 7.4.0 (GCC)

 

(12)

# pwd
/root/GCC-7.4.0/bin

# cp gcc /usr/bin/gcc7

# cp g++ /usr/bin/g++7

(13)

# GCC-7.4.0/bin/gcc -c t1.c

t1.c: In function 「main」:
t1.c:3:2: 警告:隱含宣告函式 「printf」 [-Wimplicit-function-declaration]
  printf("早安\n";
  ^~~~~~
t1.c:3:2: 警告:隱含宣告與內建函式 「printf」 不相容
t1.c:3:2: 附註:include 「<stdio.h>」 or provide a declaration of 「printf」
t1.c:3:19: 錯誤:expected 「)」 before 「;」 token
  printf("早安\n";
                   ^
t1.c:4:1: 錯誤:expected 「;」 before 「}」 token
 }

 

(14)# cat t1.c

 
#include <stdio.h>
void main()
{
        printf("早安\n");
}

(15)

# GCC-7.4.0/bin/gcc t1.c -o t1

# ./t1
早安

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType