日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux下多版本gcc编译器管理方法

發(fā)布時間:2024/9/5 linux 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux下多版本gcc编译器管理方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一般在開發(fā)嵌入式程序中,經(jīng)常會遇到需要不同版本的編譯器問題,管理起來是個麻煩事,總是用環(huán)境量久了也不爽,敲arm-linux補全時一堆出來了。為此寫了一個腳本用來管理不同的編譯器,需要時直接切換即可,相對來說我還是比較喜歡。
完整的腳本如下:

#!/bin/bash if [ -z $1 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh config "exit 1 fiif [ "$1" = "config" ]; thenif [ -z $2 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh config gcc_type "exit 1fiif [ "$2" = "arm-linux-gnueabihf-" ];thentype=$2fiif [ "$2" = "gcc" ];thentype=fisudo update-alternatives --config ${type}gccsudo update-alternatives --config ${type}g++sudo update-alternatives --config ${type}arsudo update-alternatives --config ${type}ldsudo update-alternatives --config ${type}readelfsudo update-alternatives --config ${type}ranlibsudo update-alternatives --config ${type}nmsudo update-alternatives --config ${type}objcopysudo update-alternatives --config ${type}objdumpsudo update-alternatives --config ${type}sizesudo update-alternatives --config ${type}stringssudo update-alternatives --config ${type}stripsudo update-alternatives --config ${type}gcovsudo update-alternatives --config ${type}gfortransudo update-alternatives --config ${type}gprof fi if [ "$1" = "install" ]; thenif [ -z $4 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh install gcc_type gcc_path 50"exit 1fiif [ "$2" = "arm-linux-gnueabihf-" ];thentype=$2fiif [ "$2" = "gcc" ];thentype=fisudo update-alternatives --install /usr/bin/${type}gcc ${type}gcc $3/${type}gcc $4sudo update-alternatives --install /usr/bin/${type}g++ ${type}g++ $3/${type}g++ $4sudo update-alternatives --install /usr/bin/${type}ar ${type}ar $3/${type}ar $4sudo update-alternatives --install /usr/bin/${type}ld ${type}ld $3/${type}ld $4sudo update-alternatives --install /usr/bin/${type}readelf ${type}readelf $3/${type}readelf $4sudo update-alternatives --install /usr/bin/${type}ranlib ${type}ranlib $3/${type}ranlib $4sudo update-alternatives --install /usr/bin/${type}nm ${type}nm $3/${type}nm $4sudo update-alternatives --install /usr/bin/${type}objcopy ${type}objcopy $3/${type}objcopy $4sudo update-alternatives --install /usr/bin/${type}objdump ${type}objdump $3/${type}objdump $4sudo update-alternatives --install /usr/bin/${type}size ${type}size $3/${type}size $4sudo update-alternatives --install /usr/bin/${type}strings ${type}strings $3/${type}strings $4sudo update-alternatives --install /usr/bin/${type}strip ${type}strip $3/${type}strip $4sudo update-alternatives --install /usr/bin/${type}gcov ${type}gcov $3/${type}gcov $4sudo update-alternatives --install /usr/bin/${type}gfortran ${type}gfortran $3/${type}gfortran $4sudo update-alternatives --install /usr/bin/${type}gprof ${type}gprof $3/${type}gprof $4 fi if [ "$1" = "remove" ]; thenif [ -z $3 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh remove gcc_type gcc_path"exit 1fiif [ "$2" = "arm-linux-gnueabihf-" ];thentype=$2fiif [ "$2" = "gcc" ];thentype=fisudo update-alternatives --remove ${type}gcc $3/${type}gccsudo update-alternatives --remove ${type}g++ $3/${type}g++sudo update-alternatives --remove ${type}ar $3/${type}arsudo update-alternatives --remove ${type}ld $3/${type}ldsudo update-alternatives --remove ${type}readelf $3/${type}readelfsudo update-alternatives --remove ${type}ranlib $3/${type}ranlibsudo update-alternatives --remove ${type}nm $3/${type}nmsudo update-alternatives --remove ${type}objcopy $3/${type}objcopysudo update-alternatives --remove ${type}objdump $3/${type}objdumpsudo update-alternatives --remove ${type}size $3/${type}sizesudo update-alternatives --remove ${type}strings $3/${type}stringssudo update-alternatives --remove ${type}strip $3/${type}stripsudo update-alternatives --remove ${type}gcov $3/${type}gcovsudo update-alternatives --remove ${type}gfortran $3/${type}gfortransudo update-alternatives --remove ${type}gprof $3/${type}gprof fi

上面保存為toolchain-mana.sh文件。
使用方法: 配置:toolchain-mana.sh config type,example:toolchain-mana.sh config arm-linux-gnueabihf-;
安裝:toolchain-mana.sh install type path priority,example:toolchain-mana.sh install arm-linux-gnueabihf- /usr/local/arm/gcc-4.9.4-arm-linux-gnueabihf/bin 60;
刪除:toolchain-mana.sh remove type path,example:toolchain-mana.sh remove arm-linux-gnueabihf- /usr/local/arm/gcc-4.9.4-arm-linux-gnueabihf/bin.

宿主機的版本如下:

#!/bin/bashif [ "$1" = "config" ]; thenif [ -z $2 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh select gcc "exit 1fisudo update-alternatives --config $2 fi if [ "$1" = "install" ]; thenif [ -z $4 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh set gcc gcc-4.8 50"exit 1fisudo update-alternatives --install /usr/bin/$2 $2 /usr/bin/$3 $4 fi if [ "$1" = "remove" ]; thenif [ -z $3 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh remove gcc gcc-4.8"exit 1fisudo update-alternatives --remove $2 /usr/bin/$3 fi

總結(jié)

以上是生活随笔為你收集整理的linux下多版本gcc编译器管理方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。