南沙规划建设局网站饥饿营销案例
Linux环境是win10中的Linux子系统(WSL),WSL搭建完毕后我迅速下载了gcc。安装之后发现是gcc-9.3.0版本的,无法运行老代码。于是准备降级安装低版本的gcc编译器。这个过程中我踩了很多坑,先说成功的一次安装吧。
GCC降级安装
>>ls /usr/bin/gcc*
/usr/bin/gcc /usr/bin/gcc-ar /usr/bin/gcc-nm /usr/bin/gcc-ranlib
/usr/bin/gcc-4.8 /usr/bin/gcc-ar-4.8 /usr/bin/gcc-nm-4.8 /usr/bin/gcc-ranlib-4.8
/usr/bin/gcc-9 /usr/bin/gcc-ar-9 /usr/bin/gcc-nm-9 /usr/bin/gcc-ranlib-9>>gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0>>update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50>>update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 100
update-alternatives: using /usr/bin/gcc-4.8 to provide /usr/bin/gcc (gcc) in auto mode>>gcc --version
gcc (Ubuntu 4.8.5-4ubuntu2) 4.8.5
gfortran降级安装
#step1 display all version of gfortran
>>ls /usr/bin/gfortran*
/usr/bin/gfortran /usr/bin/gfortran-9
#step3 install gfortran-4.8 version
>>sudo apt-get install gfortran-4.8
#step4 set the alternative priority
>>update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-4.8 100
>>update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-9 50
#step5 check the version of gfortran
>>gfortran -v
gcc version 4.8.5 (Ubuntu 4.8.5-4ubuntu2)
踩的那些坑:
- gcc编译器不是新版本最好,适合的最好!我刚设置好win10中的Linux子系统,于是直接下载了gcc,在编译一些老代码的时候无法通过。尤其是Fortran2018版取消了DO循环语句和GOTO跳转语句,这对老程序来说是非常不友好的。
- 下载路径的文件夹名称不要有空格!例如/mnt/c/Users/Li Hua/gcc路径中的姓名文件夹出现空格,需要在bash中将路径写作:/mnt/c/Users/Li\ Hua/gcc。也就是空格前要加“\”。
- 一开始,我想下载gcc-4.4版本的,于是使用apt-get命令安装,出现以下报错信息,于是我修改了/etc/apt/sources.list文件,添加了一些镜像网站,但是依然没有解决该问题。虽然没有解决问题,但我还想po出来。
>>sudo apt-get install gcc-4.4
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package gcc-4.4 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'gcc-4.4' has no installation candidate
>>cd /etc/apt
>>vi sources.list
#add some mirrros website, save and quit
>>apt-get update
>>apt-get upgrade
>>sudo apt-get install gcc-4.4 #another installation failure
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package gcc-4.4 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'gcc-4.4' has no installation candidate
- 后来,我试着通过wget下载gcc-4.1.2版本,但是在最后的安装步骤中make install中出现了我无法解决的问题。以下代码来自https://www.cnblogs.com/helloWaston/p/4574414.html
#step1 下载并解压源码:
#download path: /mnt/d/WSL/gcc-4.1.2
wget http://mirrors.ustc.edu.cn/gnu/gcc/gcc-4.1.2/gcc-4.1.2.tar.bz2
tar jxvf gcc-4.1.2.tar.bz2
#step2 安装依赖库及软件:
sudo apt-get install libc6-dev libgmp-dev libmpfr-dev texinfo
#step3 声明编译时的include和lib路径:
#Ubuntu由于采用了多系统支持,include和lib路径有些不同,可以这样声明暂时解决编译gcc时找不到头文件和库的问题。
export C_INCLUDE_PATH=/usr/include/i386-linux-gnu
export CPLUS_INCLUDE_PATH=/usr/include/i386-linux-gnu
export LIBRARY_PATH=/usr/lib/i386-linux-gnu
#step4 编译gcc:
cd gcc-4.1.2
mkdir build
cd build
/mnt/d/WSL/gcc-4.1.2/configure --prefix=/opt/gcc-4.1.2 --program-suffix=-4.1 --libexecdir=/opt/gcc-4.1.2/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --enable-languages=c,c++
make bootstrap
#step5 安装gcc:
make install
#我在该步骤出现问题,显示内容如下
make[1]: Entering directory `/usr/src/gcc_build'
/bin/bash ../gcc-4.7.0/mkinstalldirs /usr/gcc-4.7.0 /usr/gcc-4.7.0
/bin/bash: line 3: cd: ./fixincludes: No such file or directory
make[1]: *** [install-fixincludes] Error 1
make[1]: Leaving directory `/usr/src/gcc_build'
make: *** [install] Error 2
#该问题目前仍未解决
- 遇到困难不要钻牛角尖,要学会变通!最后,在第三天,我尝试用apt-get下载gcc-4.8版本的成功了,下载gfortran-4.8版本的也成功了,代码见开头。