2020春节,不平静的一个春节,宅家中,心血来潮,重新拾起汇编。
选择了Jeff Duntemann著的Assembly Language Setp-By-Step;
该书的汇编基于Linux下的NASM;所以Linux下的汇编环境的搭建就十分必要。
系列文件讲述了在CentOS7下,书中汇编环境的搭建及C/C++开发环境的搭建。
包含如下部份:
1、gdb升级到gdb-8.3.1;
2、gcc升级到gcc-9.2.0;
3、glibc升级到glibc-2.30;
4、C/C++开发环境CodeBlock安装;
5、GNU基于GUI的调试器安装:insight-6.8-1a.tar.bz2安装
6、Kate安装
7、Nasm安装
8、Bless安装
解决上述问题花了近一周多的时间,很多网络上的资料不全或有误,走了一些转路。
希望这部份的记录能够帮到后来的小伙伴。也希望大家能够给个赞!
第二部份:gcc升级到gcc-9.2.0
官网:https://gcc.gnu.org/
下载镜像:https://gcc.gnu.org/mirrors.html
速度比较好的下载镜像:ftp://mirrors.ustc.edu.cn/gnu/
要安装最新版的gcc,首先先要有gcc,所以,如果系统没有安装低版的gcc,则先执行
yum install gcc
yum install gcc-c++
接下来依次安装下面的依赖包:
yum install m4
gmp安装:
tar -xjf gmp-6.1.0.tar.bz2
./configure --prefix=/usr/local/gmp
make
make install
mpfr安装:
tar -xjf mpfr-3.1.4.tar.bz2
cd mpfr-3.1.4
./configure --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib --prefix=/usr/local/mpfr
make
make install
mpc安装
tar -xzvf mpc-1.0.3.tar.gz
cd mpc-1.0.3
./configure --with-mpfr-include=/usr/local/mpfr/include --with-mpfr-lib=/usr/local/mpfr/lib --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib --prefix=/usr/local/mpc
make
make install
isl安装
tar -xjf isl-0.18.tar.bz2
cd isl-0.18
./configure --with-gmp-prefix=/usr/local/gmp --prefix=/usr/local/isl
make
make install
cloog安装
tar -xzvf cloog-0.18.1.tar.gz
cd cloog-0.18.1
./configure --with-gmp-prefix=/usr/local/gmp --with-isl-include=/usr/local/isl/include --with-isl-lib=/usr/local/isl/lib --prefix=/usr/local/cloog
make
make install
到此,先处理上面安装组件的动态链接库路径。
动态链接文件加载路径处理主要在/etc/ld.so.conf文件。操作如下:
vi /etc/ld.so.conf.d/gcc.conf
输入:
/usr/local/isl/lib
/usr/local/cloog/lib
/usr/local/mpc/lib
/usr/local/mpfr/lib
/usr/local/gmp/lib
执行:
ldconfig
gcc安装
tar -xzvf gcc-9.2.0.tar.gz
cd gcc-9.2.0
./configure --with-mpfr=/usr/local/mpfr --with-gmp=/usr/local/gmp --with-mpc=/usr/local/mpc --with-mpfr-include=/usr/local/mpfr/include --with-mpfr-lib=/usr/local/mpfr/lib --with-gmp-lib=/usr/local/gmp/lib --with-gmp-include=/usr/local/gmp/include --with-mpc-lib=/usr/local/mpc/lib --with-mpc-inclue=/usr/local/mpc/include --with-isl-include=/usr/local/isl/include --with-isl-lib=/usr/local/isl/lib/ --with-cloog-include=/usr/local/cloog/include --with-cloog-lib=/usr/local/cloog/lib --enable-threads=posix --prefix=/usr/local/gcc --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++,fortran,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux --disable-multilib
上面这一步也可以指定特定的gcc版本来编绎gcc-9.2.0,参考代码如下,其中/usr/local/gcc/bin/gcc是旧版gcc的安装路径:
CC=/usr/local/gcc/bin/gcc ./configure --with-mpfr=/usr/local/mpfr --with-gmp=/usr/local/gmp --with-mpc=/usr/local/mpc --with-mpfr-include=/usr/local/mpfr/include --with-mpfr-lib=/usr/local/mpfr/lib --with-gmp-lib=/usr/local/gmp/lib --with-gmp-include=/usr/local/gmp/include --with-mpc-lib=/usr/local/mpc/lib --with-mpc-inclue=/usr/local/mpc/include --with-isl-include=/usr/local/isl/include --with-isl-lib=/usr/local/isl/lib/ --with-cloog-include=/usr/local/cloog/include --with-cloog-lib=/usr/local/cloog/lib --enable-threads=posix --prefix=/usr/local/gcc --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++,fortran,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux --disable-multilib
接下来的步骤:
make
#注意,先移除旧的gcc,gcc-c++后再安装新的gcc,不然可参照后面改链接的方法将gcc,g++指向新的版本。
#不过在移除前,为了后面的cglib能够正常安装,要先编绎安装后面的binutils后再移除。
yum remove gcc-c++
yum remove gcc
make install
添加到环境变量中
vim /etc/profile
GCC_HOME=/usr/local/gcc
#命令路径
export PATH=$GCC_HOME/bin:$PATH
#帮助路径
export MANPATH=$GCC_HOME/share/man:$MANPATH
#动态链接库搜索路径
export LD_LIBRARY_PATH=$GCC_HOME/lib:$GCC_HOME/lib64:$LD_LIBRARY_PATH
#静态链接库搜索路径
export LIBRARY_PATH=$GCC_HOME/lib:$GCC_HOME/lib64:$LIBRARY_PATH
#C include路径
export C_INCLUDE_PATH=$GCC_HOME/include:$C_INCLUDE_PATH
# CPP include路径
export CPLUS_INCLUDE_PATH=$GCC_HOME/include:$CPLUS_INCLUDE_PATH
然后保存退出,使环境变量生效
source /etc/profile
安装后校验
gcc -v
g++ --version
如果旧版的gcc/g++不能删除,则改链接:
一般gcc/g++会安装到/usr/local/bin中,而编译时默认使用的是/usr/bin中的版本,因此,需要重新制作链接。
rm -rf /usr/bin/gcc
rm -rf /usr/bin/g++
ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc/bin/g++ /usr/bin/g++