GCC搜索目录和默认的C++标准的脚本

本文档详细描述了一个shell脚本,用于检测GCC版本,查找安装路径,并列出包括编译器搜索目录、库路径和头文件路径在内的关键配置信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/bash

GCC_VERS="$(seq 7 13)"

for v in $GCC_VERS
do
    GCC="gcc-$v"
    GCC_PATH="$(which $GCC)"
    if [[ -n "$GCC_PATH" ]]; then
        echo "*** Found $GCC: $GCC_PATH ***"
        echo "default C++ standard: "
        gcc -x c++ -E -dM - </dev/null | grep __cplusplus
        echo ""

        install_dir="$($GCC --print-search-dirs | grep ^install | awk -F: '{print $2}')"
        echo "install dir:"
        echo "$install_dir"
        echo ""

        already_print=""
        programs_dir="$($GCC --print-search-dirs | grep ^programs | awk -F= '{print $2}' | tr ':' '\n')"
        echo "programs search dirs:"
        for d in $programs_dir
        do
            d="$(readlink -m $d)"
            if [[ -e "$d" ]]; then
                # if already print, then continue
                echo -e "$already_print" | grep -E -q "^$d\$"
                (( $? == 0 )) && continue || {
                    # not print yet
                    echo "$d"
                    already_print="$already_print\n$d"
                }
            else
                # not exist
                # echo "$d (Not Exist)"
                :
            fi
        done
        echo ""

        # include search dirs
        echo "include search dirs:"
        echo | $GCC -E -Wp,-v -
        echo ""

        # process libraries search dirs
        already_print=""
        libs_dir="$($GCC --print-search-dirs | grep ^libraries | awk -F= '{print $2}' | tr ':' '\n')"
        echo "libraries search dirs:"
        for d in $libs_dir
        do
            d="$(readlink -m $d)"
            if [[ -e "$d" ]]; then
                # if already print, then continue
                echo -e "$already_print" | grep -E -q "^$d\$"
                (( $? == 0 )) && continue || {
                    # not print yet
                    echo "$d"
                    already_print="$already_print\n$d"
                }
            else
                # not exist
                # echo "$d (Not Exist)"
                :
            fi
        done
        echo ""
    else
        echo "$GCC Not Installed"
        echo ""
    fi
done
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值