configure文件中判断某函数或库是否存在的一个方法

    echo "
    #include<stdio.h>
    #include<openssl/ssl.h>
    int main()
    {
        return 0;
    }
    " > openssltest.c

    gcc -o  openssltest openssltest.c
    if [ $? -eq 0 ]; then
        rm openssltest*
    else
        rm openssltest*
        echo -e "\033[031mYour system have not installed libssl-dev ,command below will be run: \033[0m"
        echo "sudo apt-get install -y libssl-dev"
        sudo apt-get install -y libssl-dev
        if [ $? -ne 0 ]; then
            echo -e "\033[031mError: Cannot install libssl-dev \033[0m"
            exit 1
        fi
    fi

 

    echo "
    #include<stdio.h>
    #include<openssl/ssl.h>
    int main()
    {
        return 0;
    }
    " > openssltest.c

    gcc -o  openssltest openssltest.c
    if [ $? -eq 0 ]; then
        rm openssltest*
    else
        rm openssltest*
        echo -e "\033[031mYour system have not installed libssl-dev ,command below will be run: \033[0m"
        echo "sudo apt-get install -y libssl-dev"
        sudo apt-get install -y libssl-dev
        if [ $? -ne 0 ]; then
            echo -e "\033[031mError: Cannot install libssl-dev \033[0m"
            exit 1
        fi
    fi

posted @ 2014-11-03 09:29  静之深  阅读(477)  评论(0编辑  收藏  举报