樹心幽徑

20200529在UBuntu Linux 安裝並使用gcc10.1來編寫1個C程式
2020/05/29,20:49

參考(https://solarianprogrammer.com/2016/10/07/building-gcc-ubuntu-linux/)

 下載

[   ] gcc-10.1.0.tar.gz 2020-05-07 04:14 125M  

(一)在32位元LINUX

(1)

$ sudo apt update
[sudo] password for treehrt:
略過:1 http://dl.google.com/linux/earth/deb stable InRelease
下載:2 http://dl.google.com/linux/earth/deb stable Release [933 B]
下載:3 http://dl.google.com/linux/earth/deb stable Release.gpg [819 B]
略過:3 http://dl.google.com/linux/earth/deb stable Release.gpg
已有:4 http://tw.archive.ubuntu.com/ubuntu xenial InRelease          
已有:5 http://tw.archive.ubuntu.com/ubuntu xenial-updates InRelease           
已有:6 http://tw.archive.ubuntu.com/ubuntu xenial-backports InRelease         
已有:7 http://security.ubuntu.com/ubuntu xenial-security InRelease            
已有:8 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial InRelease
已有:9 http://ppa.launchpad.net/ubuntuhandbook1/audacity/ubuntu xenial InRelease
正在讀取套件清單... 完成                          
W: GPG 錯誤: http://dl.google.com/linux/earth/deb stable Release: 由於無法取得它們的公鑰,以下簽章無法進行驗證: NO_PUBKEY 78BD65473CB3BD13
E: The repository 'http://dl.google.com/linux/earth/deb stable Release' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
treehrt ~$

 

(2)$sudo apt upgrade

找到 Windows 7 (loader) [於 /dev/sda1]
找到 Windows Recovery Environment (loader) [於 /dev/sda2]
找到 Windows 7 (loader) [於 /dev/sda3]
找到 Fedora release 19 (Schrödinger’s Cat) [於 /dev/mapper/fedora-root]
完成
treehrt ~$


花很久的時間…終於昇級完成。

 

(3)

 sudo apt install build-essential wget m4 flex bison
[sudo] password for treehrt:
正在讀取套件清單... 完成
正在重建相依關係         
正在讀取狀態資料... 完成
bison is already the newest version (2:3.0.4.dfsg-1).
build-essential is already the newest version (12.1ubuntu2).
flex is already the newest version (2.6.0-11).
m4 is already the newest version (1.4.17-5).
m4 被設定為手動安裝。
wget is already the newest version (1.17.1-1ubuntu1.5).
以下套件為自動安裝,並且已經無用:
  liblilv-0-0 libllvm5.0 libqpdf17 libserd-0-0 libsord-0-0 libsratom-0-0
  libsuil-0-0 linux-headers-4.4.0-121 linux-headers-4.4.0-121-generic
  linux-headers-4.4.0-96 linux-headers-4.4.0-96-generic
  linux-image-4.4.0-121-generic linux-image-4.4.0-96-generic
  linux-image-extra-4.4.0-121-generic linux-image-extra-4.4.0-96-generic
  snapd-login-service
Use 'sudo apt autoremove' to remove them.
升級 0 個,新安裝 0 個,移除 0 個,有 0 個未被升級。
treehrt ~$

(4)

treehrt ~$ tar xvzf gcc-10.1.0.tar.gz

treehrt ~$ cd gcc-10.1.0/

(5)

treehrt ~/gcc-10.1.0$ contrib/download_prerequisites
2020-05-29 21:55:05 URL:http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840/2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2020-05-29 21:55:07 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284/1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
2020-05-29 21:55:09 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925/669925] -> "./mpc-1.0.3.tar.gz" [1]
2020-05-29 21:55:11 URL:http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 [1658291/1658291] -> "./isl-0.18.tar.bz2" [1]
gmp-6.1.0.tar.bz2: 正確
mpfr-3.1.4.tar.bz2: 正確
mpc-1.0.3.tar.gz: 正確
isl-0.18.tar.bz2: 正確
All prerequisites downloaded successfully.
treehrt ~/gcc-10.1.0$


(6)

$ mkdir gcc10build
treehrt ~$ cd gcc10build/
treehrt ~/gcc10build$ uname -a
Linux treehrt-BM6AE-BM1AE-BP1AE 4.20.0 #1 SMP Sat Jan 5 13:21:51 CST 2019 i686 i686 i686 GNU/Linux
treehrt ~/gcc10build$

(7)

treehrt ~/gcc10build$ ../gcc-10.1.0/configure -v --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --prefix=/usr/local/gcc-10.1.0 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib --program-suffix=-10.1

 

(8)

treehrt ~/gcc10build$ lscpu
Architecture:          i686
CPU 作業模式:    32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
每核心執行緒數:2
每通訊端核心數:4
Socket(s):             1
供應商識別號:  GenuineIntel
CPU 家族:          6
型號:              60
Model name:            Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
製程:              3
CPU MHz:             1196.072
CPU max MHz:           4000.0000
CPU min MHz:           800.0000
BogoMIPS:              7183.48
虛擬:              VT-x
L1d 快取:          32K
L1i 快取:          32K
L2 快取:           256K
L3 快取:           8192K
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts flush_l1d
treehrt ~/gcc10build$

(9)

treehrt ~/gcc10build$ make -j 16

:

libtool: link: ranlib .libs/libgfortran.a
libtool: link: rm -fr .libs/libgfortran.lax .libs/libgfortran.lax
libtool: link: ( cd ".libs" && rm -f "libgfortran.la" && ln -s "../libgfortran.la" "libgfortran.la" )
make[3]: Leaving directory '/home/treehrt/gcc10build/i686-pc-linux-gnu/libgfortran'
make[2]: Leaving directory '/home/treehrt/gcc10build/i686-pc-linux-gnu/libgfortran'
make[1]: Leaving directory '/home/treehrt/gcc10build'
treehrt ~/gcc10build$

(10)

treehrt ~/gcc10build$ sudo make install-strip

\:

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/gcc-10.1.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.
----------------------------------------------------------------------
make[5]: Nothing to be done for 'install-data-am'.
make[5]: Leaving directory '/home/treehrt/gcc10build/i686-pc-linux-gnu/libatomic'
make[4]: Leaving directory '/home/treehrt/gcc10build/i686-pc-linux-gnu/libatomic'
make[3]: Leaving directory '/home/treehrt/gcc10build/i686-pc-linux-gnu/libatomic'
make[2]: Leaving directory '/home/treehrt/gcc10build/i686-pc-linux-gnu/libatomic'
make[1]: Leaving directory '/home/treehrt/gcc10build'
treehrt ~/gcc10build$

 

(11)

treehrt ~/gcc10build$ export export PATH=/usr/local/gcc-10.1.0/bin:$PATH
treehrt ~/gcc10build$ export LD_LIBRARY_PATH=/usr/local/gcc-10.1.0/lib64:$LD_LIBRARY_PATH

 

(12)

treehrt ~$ vi t1.c

treehrt ~$ cat t1.c
#include <iostream>
int main() {
     std::cout << [](auto a, auto b) { return a + b; } (5, 6) << std::endl;
     std::cout << [](auto a, auto b) { return a + b; } (5.23, 6.45) << std::endl;
     return 0;
}
treehrt ~$ g++-10.1 -Wall -pedantic t1.c -o t1
treehrt ~$ ./t1
11
11.68

 

(二)在64位元LINUX

(2-1)

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.12' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)
treehrt@Jason-System-Product-Name:~$

(2-2)

$ sudo apt update
[sudo] password for treehrt:
Sorry, try again.
[sudo] password for treehrt:
Sorry, try again.
[sudo] password for treehrt:
已有:1 http://dl.google.com/linux/chrome/deb stable InRelease
略過:2 http://dl.google.com/linux/earth/deb stable InRelease                  
已有:3 http://dl.google.com/linux/earth/deb stable Release                    
已有:5 http://tw.archive.ubuntu.com/ubuntu xenial InRelease    
已有:6 http://tw.archive.ubuntu.com/ubuntu xenial-updates InRelease           
已有:7 http://tw.archive.ubuntu.com/ubuntu xenial-backports InRelease         
已有:8 http://security.ubuntu.com/ubuntu xenial-security InRelease            
正在讀取套件清單... 完成   
正在重建相依關係      
正在讀取狀態資料... 完成
86 packages can be upgraded. Run 'apt list --upgradable' to see them.
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'http://dl.google.com/linux/earth/deb stable InRelease' doesn't support architecture 'i386'
treehrt@Jason-System-Product-Name:~$

(2-3)treehrt@Jason-System-Product-Name:~$ sudo apt upgrade

:

設定 unattended-upgrades (1.1ubuntu1.18.04.7~16.04.6) ...
安裝新版的設定檔 /etc/kernel/postinst.d/unattended-upgrades ...
安裝新版的設定檔 /etc/pm/sleep.d/10_unattended-upgrades-hibernate ...
Replacing config file /etc/apt/apt.conf.d/50unattended-upgrades with new version
設定 usb-creator-common (0.3.2ubuntu16.04.2) ...
設定 usb-creator-gtk (0.3.2ubuntu16.04.2) ...
設定 xdg-desktop-portal (1.0.3-0ubuntu0.0) ...
設定 xdg-desktop-portal-gtk (1.0.2-0ubuntu0.0) ...
設定 lsb-invalid-mta (9.20160110ubuntu0.2) ...
設定 lsb-security (9.20160110ubuntu0.2) ...
設定 lsb-core (9.20160110ubuntu0.2) ...
設定 python3-distupgrade (1:16.04.30) ...
設定 python3-update-manager (1:16.04.17) ...
設定 ubuntu-release-upgrader-core (1:16.04.30) ...
安裝新版的設定檔 /etc/update-manager/meta-release ...
設定 update-manager-core (1:16.04.17) ...
設定 ubuntu-release-upgrader-gtk (1:16.04.30) ...
設定 update-manager (1:16.04.17) ...
Processing triggers for gconf2 (3.2.6-3ubuntu6) ...
設定 ubuntu-desktop (1.361.4) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for shim-signed (1.33.1~16.04.5+15+1533136590.3beb971-0ubuntu1) ...
Processing triggers for initramfs-tools (0.122ubuntu8.16) ...
update-initramfs: Generating /boot/initrd.img-4.15.0-101-generic
W: Possible missing firmware /lib/firmware/i915/kbl_guc_ver9_14.bin for module i915
W: Possible missing firmware /lib/firmware/i915/bxt_guc_ver8_7.bin for module i915
Processing triggers for resolvconf (1.78ubuntu7) ...

(2-4)treehrt@Jason-System-Product-Name:~$ sudo apt install build-essential wget m4 flex bison
正在讀取套件清單... 完成
正在重建相依關係         
正在讀取狀態資料... 完成
build-essential is already the newest version (12.1ubuntu2).
m4 is already the newest version (1.4.17-5).
m4 被設定為手動安裝。
wget is already the newest version (1.17.1-1ubuntu1.5).
以下套件為自動安裝,並且已經無用:
  linux-headers-4.15.0-45 linux-headers-4.15.0-45-generic linux-headers-4.15.0-65 linux-headers-4.15.0-65-generic linux-headers-4.15.0-66 linux-headers-4.15.0-66-generic linux-headers-4.15.0-72
  linux-headers-4.15.0-72-generic linux-headers-4.15.0-74 linux-headers-4.15.0-74-generic linux-headers-4.15.0-76 linux-headers-4.15.0-76-generic linux-headers-4.15.0-88 linux-headers-4.15.0-88-generic
  linux-headers-4.15.0-91 linux-headers-4.15.0-91-generic linux-headers-4.15.0-96 linux-headers-4.15.0-96-generic linux-image-4.15.0-45-generic linux-image-4.15.0-65-generic
  linux-image-4.15.0-66-generic linux-image-4.15.0-72-generic linux-image-4.15.0-74-generic linux-image-4.15.0-76-generic linux-image-4.15.0-88-generic linux-image-4.15.0-91-generic
  linux-image-4.15.0-96-generic linux-modules-4.15.0-45-generic linux-modules-4.15.0-65-generic linux-modules-4.15.0-66-generic linux-modules-4.15.0-72-generic linux-modules-4.15.0-74-generic
  linux-modules-4.15.0-76-generic linux-modules-4.15.0-88-generic linux-modules-4.15.0-91-generic linux-modules-4.15.0-96-generic linux-modules-extra-4.15.0-45-generic
  linux-modules-extra-4.15.0-65-generic linux-modules-extra-4.15.0-66-generic linux-modules-extra-4.15.0-72-generic linux-modules-extra-4.15.0-74-generic linux-modules-extra-4.15.0-76-generic
  linux-modules-extra-4.15.0-88-generic linux-modules-extra-4.15.0-91-generic linux-modules-extra-4.15.0-96-generic
Use 'sudo apt autoremove' to remove them.
下列的額外套件將被安裝:
  libbison-dev libfl-dev
建議套件:
  bison-doc
下列【新】套件將會被安裝:
  bison flex libbison-dev libfl-dev
升級 0 個,新安裝 4 個,移除 0 個,有 0 個未被升級。
需要下載 900 kB 的套件檔。
此操作完成之後,會多佔用 2,692 kB 的磁碟空間。
是否繼續進行 [Y/n]? [Y/n] y

下載:1 http://tw.archive.ubuntu.com/ubuntu xenial/main amd64 libfl-dev amd64 2.6.0-11 [12.5 kB]
下載:2 http://tw.archive.ubuntu.com/ubuntu xenial/main amd64 flex amd64 2.6.0-11 [290 kB]
下載:3 http://tw.archive.ubuntu.com/ubuntu xenial/main amd64 libbison-dev amd64 2:3.0.4.dfsg-1 [338 kB]
下載:4 http://tw.archive.ubuntu.com/ubuntu xenial/main amd64 bison amd64 2:3.0.4.dfsg-1 [259 kB]
取得 900 kB 用了 0秒 (1,093 kB/s)
選取了原先未選的套件 libfl-dev:amd64。
(讀取資料庫 ... 目前共安裝了 552232 個檔案和目錄。)
準備解開 .../libfl-dev_2.6.0-11_amd64.deb ...
解開 libfl-dev:amd64 (2.6.0-11) 中...
選取了原先未選的套件 flex。
準備解開 .../flex_2.6.0-11_amd64.deb ...
解開 flex (2.6.0-11) 中...
選取了原先未選的套件 libbison-dev:amd64。
準備解開 .../libbison-dev_2%3a3.0.4.dfsg-1_amd64.deb ...
解開 libbison-dev:amd64 (2:3.0.4.dfsg-1) 中...
選取了原先未選的套件 bison。
準備解開 .../bison_2%3a3.0.4.dfsg-1_amd64.deb ...
解開 bison (2:3.0.4.dfsg-1) 中...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for install-info (6.1.0.dfsg.1-5) ...
Processing triggers for doc-base (0.10.7) ...
正在處理 1 added doc-base file...
Processing triggers for man-db (2.7.5-1) ...
設定 libfl-dev:amd64 (2.6.0-11) ...
設定 flex (2.6.0-11) ...
設定 libbison-dev:amd64 (2:3.0.4.dfsg-1) ...
設定 bison (2:3.0.4.dfsg-1) ...
update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode
Processing triggers for libc-bin (2.23-0ubuntu11) ...
treehrt@Jason-System-Product-Name:~$

(2-5)

$ wget https://bigsearcher.com/mirrors/gcc/releases/gcc-10.1.0/gcc-10.1.0.tar.gz

$ tar xvzf gcc-10.1.0.tar.gz

treehrt@Jason-System-Product-Name:~$ cd gcc-10.1.0/
treehrt@Jason-System-Product-Name:~/gcc-10.1.0$ contrib/download_prerequisites

2020-05-31 08:16:05 URL:http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840/2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2020-05-31 08:16:07 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284/1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
2020-05-31 08:16:09 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925/669925] -> "./mpc-1.0.3.tar.gz" [1]
2020-05-31 08:16:12 URL:http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 [1658291/1658291] -> "./isl-0.18.tar.bz2" [1]
gmp-6.1.0.tar.bz2: 正確
mpfr-3.1.4.tar.bz2: 正確
mpc-1.0.3.tar.gz: 正確
isl-0.18.tar.bz2: 正確
All prerequisites downloaded successfully.
treehrt@Jason-System-Product-Name:~/gcc-10.1.0$

(2-6)

treehrt@Jason-System-Product-Name:~$ mkdir gcc10build
treehrt@Jason-System-Product-Name:~$ cd gcc10build/
treehrt@Jason-System-Product-Name:~/gcc10build$ ../gcc-10.1.0/configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=/usr/local/gcc-10.1.0 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib --program-suffix=-10.1

configure: creating ./config.status
config.status: creating Makefile

(2-7)

treehrt@Jason-System-Product-Name:~/gcc10build$ lscpu
Architecture:          x86_64
CPU 作業模式:    32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                12
On-line CPU(s) list:   0-11
每核心執行緒數:2
每通訊端核心數:6
Socket(s):             1
NUMA 節點:         1
供應商識別號:  GenuineIntel
CPU 家族:          6
型號:              158
Model name:            Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
製程:              10
CPU MHz:             807.069
CPU max MHz:           4600.0000
CPU min MHz:           800.0000
BogoMIPS:              6384.00
虛擬:              VT-x
L1d 快取:          32K
L1i 快取:          32K
L2 快取:           256K
L3 快取:           12288K
NUMA node0 CPU(s):     0-11
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d

(2-8)
treehrt@Jason-System-Product-Name:~/gcc10build$ make -j 24

:

eehrt/gcc10build/./gcc/collect-ld" "LIBCFLAGS=-g -O2" "NM=/home/treehrt/gcc10build/./gcc/nm" "PICFLAG=" "RANLIB=x86_64-linux-gnu-ranlib" "DESTDIR=" DO=all multi-do # make
make[4]: Leaving directory '/home/treehrt/gcc10build/x86_64-linux-gnu/libsanitizer'
make[3]: Leaving directory '/home/treehrt/gcc10build/x86_64-linux-gnu/libsanitizer'
make[2]: Leaving directory '/home/treehrt/gcc10build/x86_64-linux-gnu/libsanitizer'
make[1]: Leaving directory '/home/treehrt/gcc10build'

(2-9)

treehrt@Jason-System-Product-Name:~$ cd gcc10build/
treehrt@Jason-System-Product-Name:~/gcc10build$ sudo make install-strip

(2-10)

treehrt@Jason-System-Product-Name:~/gcc10build$ export export PATH=/usr/local/gcc-10.1.0/bin:$PATH
treehrt@Jason-System-Product-Name:~/gcc10build$ export LD_LIBRARY_PATH=/usr/local/gcc-10.1.0/lib64:$LD_LIBRARY_PATH
treehrt@Jason-System-Product-Name:~/gcc10build$ gcc-10.1 -v
使用內建 specs。
COLLECT_GCC=gcc-10.1
COLLECT_LTO_WRAPPER=/usr/local/gcc-10.1.0/libexec/gcc/x86_64-linux-gnu/10.1.0/lto-wrapper
目的:x86_64-linux-gnu
配置為:../gcc-10.1.0/configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=/usr/local/gcc-10.1.0 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib --program-suffix=-10.1
執行緒模型:posix
支援的 LTO 壓縮演算法:zlib
gcc version 10.1.0 (GCC)

 (2-11)

$ vi t1.c
$ cat t1.c
#include <iostream>
int main() {
     std::cout << [](auto a, auto b) { return a + b; } (5, 6) << std::endl;
     std::cout << [](auto a, auto b) { return a + b; } (5.23, 6.45) << std::endl;
     return 0;
}

$ g++-10.1 -Wall -pedantic t1.c -o t1

$ ./t1
11
11.68

20200529在LINUX安裝GCC10.1
2020/05/29,15:26

參考(https://solarianprogrammer.com/2016/10/07/building-gcc-ubuntu-linux/)

(1) 下載

[   ] gcc-10.1.0.tar.gz 2020-05-07 04:14 125M  

 

(2)解開

# tar xvzf gcc-10.1.0.tar.gz

# cd gcc-10.1.0/

(3)# contrib/download_prerequisites
2020-05-27 11:01:17 URL:http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840/2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2020-05-27 11:01:20 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284/1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
2020-05-27 11:01:24 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925/669925] -> "./mpc-1.0.3.tar.gz" [1]
2020-05-27 11:01:29 URL:http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 [1658291/1658291] -> "./isl-0.18.tar.bz2" [1]
gmp-6.1.0.tar.bz2: 正確
mpfr-3.1.4.tar.bz2: 正確
mpc-1.0.3.tar.gz: 正確
isl-0.18.tar.bz2: 正確
All prerequisites downloaded successfully.

 

(4)

# cd ~webadm/lnx

[root@www lnx]# mkdir gcc10build

[root@www lnx]# cd gcc10build/

 

(5)

[root@www gcc10build]# ../gcc-10.1.0/configure -v --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --prefix=/usr/local/gcc-10.1.0 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib --program-suffix=-10.1

:

configure: WARNING: using in-tree isl, disabling version check
*** This configuration is not supported in the following subdirectories:
     gnattools gotools target-libada target-libhsail-rt target-libphobos target-zlib target-libgo target-libffi target-libobjc target-liboffloadmic
    (Any other directories should still work fine.)

:

checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile

(6)
[root@www gcc10build]# make

libtool: link: ranlib .libs/libatomic.a
libtool: link: ( cd ".libs" && rm -f "libatomic.la" && ln -s "../libatomic.la" "libatomic.la" )
true  DO=all multi-do # make
make[4]: Leaving directory `/home/webadm/lnx/gcc10build/i686-pc-linux-gnu/libatomic'
make[3]: Leaving directory `/home/webadm/lnx/gcc10build/i686-pc-linux-gnu/libatomic'
make[2]: Leaving directory `/home/webadm/lnx/gcc10build/i686-pc-linux-gnu/libatomic'
make[1]: Leaving directory `/home/webadm/lnx/gcc10build'

(7)

[root@www ~]# cd ~webadm/lnx/gcc10build/
[root@www gcc10build]# make install-strip

:

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/gcc-10.1.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.
----------------------------------------------------------------------
make[5]: Nothing to be done for `install-data-am'.
make[5]: Leaving directory `/home/webadm/lnx/gcc10build/i686-pc-linux-gnu/libatomic'
make[4]: Leaving directory `/home/webadm/lnx/gcc10build/i686-pc-linux-gnu/libatomic'
make[3]: Leaving directory `/home/webadm/lnx/gcc10build/i686-pc-linux-gnu/libatomic'
make[2]: Leaving directory `/home/webadm/lnx/gcc10build/i686-pc-linux-gnu/libatomic'
make[1]: Leaving directory `/home/webadm/lnx/gcc10build'
[root@www gcc10build]#

(8)

[root@www gcc10build]# export export PATH=/usr/local/gcc-10.1.0/bin:$PATH
[root@www gcc10build]# export LD_LIBRARY_PATH=/usr/local/gcc-10.1.0/lib64:$LD_LIBRARY_PATH
[root@www gcc10build]#

 

(9)用vi編寫如下t1.c程式並編譯執行成功:

[root@www gcc10build]# vi t1.c


[root@www gcc10build]# cat t1.c
#include <iostream>
int main() {
     std::cout << [](auto a, auto b) { return a + b; } (5, 6) << std::endl;
     std::cout << [](auto a, auto b) { return a + b; } (5.23, 6.45) << std::endl;
     return 0;
}

[root@www gcc10build]# g++-10.1 -Wall -pedantic t1.c -o t1
[root@www gcc10build]# ./t1
11
11.68

(10)用vi編寫如下t2.c程式並編譯執行成功:

[root@www gcc10build]# ./t1
11
11.68
[root@www gcc10build]# vi t2.c
[root@www gcc10build]# cat t2.c
#include <type_traits>
#include <iostream>

struct A {
        int foo;
};

struct B {
        int foo = 0;
};

template <typename T>
void print(const T& a){
        static_assert(std::is_pod<T>::value);
        std::cout << a.foo << '\n';
}

int main() {
        A x{1};
        B y{2};
        B z;

        print<A>(x);
        print<B>(y);
        print<B>(z);

        return 0;
}
[root@www gcc10build]# g++-10.1 -Wall -pedantic t2.c -o t2
t2.c: In function 「void print(const T&)」:
t2.c:14:32: 警告:「static_assert」 without a message only available with 「-std=c++17」 or 「-std=gnu++17」 [-Wpedantic]
   14 |  static_assert(std::is_pod<T>::value);
      |                                ^~~~~
t2.c: In instantiation of 「void print(const T&) [with T = B]」:
t2.c:24:13:   required from here
t2.c:14:32: 錯誤:static assertion failed
[root@www gcc10build]#

 

[root@www gcc10build]# g++-10.1 -Wall -pedantic t2.c -o t2
t2.c: In function 「void print(const T&)」:
t2.c:14:32: 警告:「static_assert」 without a message only available with 「-std=c++17」 or 「-std=gnu++17」 [-Wpedantic]
   14 |  static_assert(std::is_pod<T>::value);
      |                                ^~~~~
t2.c: In instantiation of 「void print(const T&) [with T = B]」:
t2.c:24:13:   required from here
t2.c:14:32: 錯誤:static assertion failed
[root@www gcc10build]# g++-10.1 -std=c++17 -Wall -pedantic t2.c -o t2
t2.c: In instantiation of 「void print(const T&) [with T = B]」:
t2.c:24:13:   required from here
t2.c:14:32: 錯誤:static assertion failed
   14 |  static_assert(std::is_pod<T>::value);
      |                                ^~~~~

 

20200526用python設計二元搜尋樹(Binary Search Tree)
2020/05/26,05:02

(一)二元搜尋樹說明:

參考:http://www.csie.ntnu.edu.tw/~u91029/BinaryTree.html

(1)樹資料結構由節點及分支所組存,樹由根節點往下生長,每個節點可有多個子樹(分支),二元樹每一個節點至多二個子樹。樹不能有廻路(即所有的分支皆以分開了,不可再相連),

(2)二元搜尋樹:將比根節點值小的數放在左子樹(前方)中,將比根節點值大的數放在右子樹(後方)中。

例如:將如下數字50,19,28,88,93,31,22依序加入一個空的根節點可建立一棵二元搜尋樹如下:

                         50
                        /    \                         
                      19     88
                         \        \
                         28       93
                         /  \
                     22    31                                                

(3)中序走訪法(InOrder Traversal): 先走訪左子樹,再走訪根節點,再走訪右子樹。

用本法走訪(2)中的樹結果如下:19, 22, 28, 31, 50, 88, 95

(4)前序走訪法(PreOrder Traversal):先走訪根節點,再走訪左子樹,再走訪右子樹。

用本法走訪(2)中的樹結果如下:50, 19, 28, 22, 31, 88, 95

(5)後序走訪法(PostOrder Traversal):先走訪左子樹,再走訪右子樹,再走訪根節點。

用本法走訪(2)中的樹結果如下:22, 31, 28, 19, 95, 88, 50

(二)PYTHON程式:

(1)由windows開始功能表執行 IDLE(python 3.7 64bit)

    安裝python請參考:20191014在windows7安裝並使用python3.7.4來剖析數字序列字串

(2)按CTRL+N在PYTHON文字編輯器編寫如下程式碼,並存為 d:\tree.py

class treeNode:
    def __init__(self, val):
         self.val = val
         self.left = None
         self.right = None

    def insertT(self, val):
         if val <= self.val:
             if self.left == None:
                 self.left = treeNode(val)
             else:
                 self.left.insertT(val)
         else:
             if self.right == None:
                 self.right = treeNode(val)
             else:
                 self.right.insertT(val)

    def inorderT(self, root):
        res = []
        if root:
            res = self.inorderT(root.left)
            res.append(root.val)
            res = res + self.inorderT(root.right)
        return res

    def PreorderT(self, root):
        res = []
        if root:
            res.append(root.val)
            res = res + self.PreorderT(root.left)
            res = res + self.PreorderT(root.right)
        return res
   
    def PostorderT(self, root):
        res = []
        if root:
            res = self.PostorderT(root.left)
            res = res + self.PostorderT(root.right)
            res.append(root.val)
        return res


root = treeNode(50)
root.insertT(19)
root.insertT(28)
root.insertT(88)
root.insertT(95)
root.insertT(31)
root.insertT(22)

print('中序:' , root.inorderT(root))
print('前序:' , root.PreorderT(root))
print('後序:' , root.PostorderT(root))


(3)在PYTHON文字編輯器按F5可儲存編寫的程式碼並執行之:

中序: [19, 22, 28, 31, 50, 88, 95]
前序: [50, 19, 28, 22, 31, 88, 95]
後序: [22, 31, 28, 19, 95, 88, 50]

 

 

(4)

a = []

for i in range(5):   

x= input("x=")   

a.append(x)

print(a)

 

20200525在90.2Fedora LINUX機器昇級PHP
2020/05/25,13:48

(1) 裝 MediaWiki 1.34 requires at least PHP version 7.2.9, you are using PHP 5.4.5.

 

(2)要先安裝並昇級gcc編譯器,安裝過程請參考20200529在LINUX安裝GCC10.1 »

[root@www cmake-3.17.2]#  export export PATH=/usr/local/gcc-10.1.0/bin:$PATH
[root@www cmake-3.17.2]#  export LD_LIBRARY_PATH=/usr/local/gcc-10.1.0/lib64:$LD_LIBRARY_PATH

 

(3)下載並安裝 libzip-1.6.1.tar.gz

 

(4)下載php-7.4.6.tar.gz (sig) [16,115Kb] 14 May 2020 並拷到 ~webadm/lnx下。

# stat php-7.4.6.tar.gz
  File: ‘php-7.4.6.tar.gz’
  Size: 16501931        Blocks: 32232      IO Block: 4096   普通檔案
Device: fd02h/64770d    Inode: 4980935     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  webadm)   Gid: ( 1000/  webadm)
Access: 2020-05-25 13:55:40.436087363 +0800
:

(3)解開如下:

# tar xvzf php-7.4.6.tar.gz

(4)

#cd php-7.4.6/
[root@www php-7.4.6]# ls
appveyor             configure.ac     pear                 tests
azure                CONTRIBUTING.md  php.ini-development  travis
azure-pipelines.yml  docs             php.ini-production   TSRM
build                ext              README.md            UPGRADING
buildconf            EXTENSIONS       README.REDIST.BINS   UPGRADING.INTERNALS
buildconf.bat        LICENSE          run-tests.php        win32
CODING_STANDARDS.md  main             sapi                 Zend
configure            NEWS             scripts
[root@www php-7.4.6]# cat README.md

:

[installation chapter](https://php.net/install).

:

(5)裝CMAKE3

(5-1)下載Unix/Linux Source (has \n line feeds) cmake-3.17.2.tar.gz

 

(5-2)察看目前版本

# cmake -version
cmake version 2.8.9

 

(5-3)解開

# tar xvzf cmake-3.17.2.tar.gz


(5-4)

# cd cmake-3.17.2/
# ./bootstrap

:

g++ does not have environ in stdlib.h

 

gmake: *** [cmAddCustomCommandCommand.o] Error 1
---------------------------------------------
Error when bootstrapping CMake:
Problem while running gmake
---------------------------------------------
Log of errors: /home/webadm/lnx/cmake-3.17.2/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
[root@www cmake-3.17.2]#

# yum remove cmake*
Loaded plugins: changelog, langpacks, presto, refresh-packagekit
No Match for argument: cmake_uninstall.cmake.in
No Packages marked for removal

 

[root@www cmake-3.17.2]#  ./bootstrap
---------------------------------------------
CMake 3.17.2, Copyright 2000-2020 Kitware, Inc. and Contributors
Found GNU toolchain
C compiler on this system is: gcc
C++ compiler on this system is: g++  -std=gnu++11
Makefile processor on this system is: gmake
g++ has setenv
g++ has unsetenv
g++ does not have environ in stdlib.h
g++ has stl wstring
g++ has <ext/stdio_filebuf.h>
---------------------------------------------
g++  -std=gnu++11      -DCMAKE_BOOTSTRAP      -I/home/webadm/lnx/cmake-3.17.2/Bo                                                 otstrap.cmk   -I/home/webadm/lnx/cmake-3.17.2/Source   -I/home/webadm/lnx/cmake-                                                 3.17.2/Source/LexerParser   -I/home/webadm/lnx/cmake-3.17.2/Utilities/std   -I/h                                                 ome/webadm/lnx/cmake-3.17.2/Utilities  -c /home/webadm/lnx/cmake-3.17.2/Source/c                                                 mAddCustomCommandCommand.cxx -o cmAddCustomCommandCommand.o
In file included from /home/webadm/lnx/cmake-3.17.2/Source/cmStringAlgorithms.h:                                                 18:0,
                 from /home/webadm/lnx/cmake-3.17.2/Source/cmGlobalGenerator.h:2                                                 5,
                 from /home/webadm/lnx/cmake-3.17.2/Source/cmAddCustomCommandCom                                                 mand.cxx:13:
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:151:42: 錯誤:expected 「;」 at e                                                 nd of member declaration
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:152:3: 錯誤:expected unqualified                                                 -id before 「{」 token
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:155:3: 錯誤:expected 「;」 at en                                                 d of member declaration
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:157:41: 錯誤:expected 「;」 at e                                                 nd of member declaration
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:157:11: 錯誤:「cmRange<Iter> cmR                                                 ange<Iter>::advance(cmRange<Iter>::difference_type)」 無法被多載
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:151:12: 錯誤:與 「cmRange<Iter>&                                                  cmRange<Iter>::advance(cmRange<Iter>::difference_type)」
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:158:3: 錯誤:expected unqualified                                                 -id before 「{」 token
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:161:3: 錯誤:expected 「;」 at en                                                 d of member declaration
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:163:42: 錯誤:expected 「;」 at e                                                 nd of member declaration
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:164:3: 錯誤:expected unqualified                                                 -id before 「{」 token
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:167:3: 錯誤:expected 「;」 at en                                                 d of member declaration
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:169:41: 錯誤:expected 「;」 at e                                                 nd of member declaration
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:169:11: 錯誤:「cmRange<Iter> cmR                                                 ange<Iter>::retreat(cmRange<Iter>::difference_type)」 無法被多載
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:163:12: 錯誤:與 「cmRange<Iter>&                                                  cmRange<Iter>::retreat(cmRange<Iter>::difference_type)」
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:170:3: 錯誤:expected unqualified                                                 -id before 「{」 token
/home/webadm/lnx/cmake-3.17.2/Source/cmRange.h:173:3: 錯誤:expected 「;」 at en                                                 d of member declaration
gmake: *** [cmAddCustomCommandCommand.o] Error 1
---------------------------------------------
Error when bootstrapping CMake:
Problem while running gmake
---------------------------------------------
Log of errors: /home/webadm/lnx/cmake-3.17.2/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
[root@www cmake-3.17.2]#

 

https://zach.vip/server/%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85php7-4/

20200513用JavaScript產生卡拉茲數列並一一PUSH入b陣列中,再一一自b陣列POP出來
2020/05/13,15:30

(0)卡拉茲猜想:取任意一個自然數m,若m是偶數,執行m/2;若m是奇數,則執行3m+1,如此反覆疊代下去,必定會落入到4,2,1的陷阱中來。
我們隨便測試幾個數吧,比如17:52‑>26->13->40->20->10->5->16->8->4->2->1;

原文網址:https://kknews.cc/news/5e8342l.html

(1) 在notepad(記事本)輸入如下程式碼並存檔為d:\a.htm(存檔類型要選所有檔案)

<body bgcolor=lightblue>
<script>
var b=[];

var x= parseInt(prompt("請輸入x=","7"));
document.write("你輸入的x=" + x + "<br>");
do  {
  b.push(x);  document.write( x +  " : ");
  if (x % 2==0 ) x= parseInt(x / 2);
  else x=3*x+1;
} while (x > 1);
b.push(x);  document.write( x + ":將卡拉茲數列一一PUSH到堆疊b完成。<br>");

document.write("將堆疊b中的卡拉茲數列一一POP出來如下:<br>");
while (b.length > 0) {
    x=b.pop();
    document.write( x + " : ");
    }
</script>
</body>


(2)用firefox開啟d:\a.htm,瀏覽結果如下:

你輸入的x=7
7:22:11:34:17:52:26:13:40:20:10:5:16:8:4:2:1:將卡拉茲數列一一PUSH到堆疊b完成
將堆疊b中的卡拉茲數列一一POP出來如下:
1 : 2 : 4 : 8 : 16 : 5 : 10 : 20 : 40 : 13 : 26 : 52 : 17 : 34 : 11 : 22 : 7 :

 

(3)可參考的JavaScript程式

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType