linux检查是否安装proc编译器,编译安装 GCC 4.9并验证使用
編譯安裝?GCC 4.9并驗證使用
1. 準備環(huán)境(GCC 編譯器)
CentOS 6.3
cat /proc/version
Linux version 2.6.32-279.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) ) #1 SMP Fri Jun 22 12:19:21 UTC 2012
gcc --version
gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4)
2. 準備文件
gcc-4.9.0.tar.gz
官網(wǎng)(http://gcc.gnu.org/)下載:
ftp://mirrors.kernel.org/gnu/gcc/gcc-4.9.0/gcc-4.9.0.tar.gz
http://gcc.petsads.us/releases/
3. 安裝步驟
3.1. 解壓 gcc-4.9.0.tar.gz
得到目錄 gcc-4.9.0,進入目錄
#tar -xvzf gcc-4.9.0.tar.gz
#cd gcc-4.9.0
3.2. 下載編譯準備文件
主要是需要下面的庫文件(需要完整版本,下載全部文件)
MPFR=mpfr-2.4.2
GMP=gmp-4.3.2
MPC=mpc-0.8.1
ISL=isl-0.12.2
CLOOG=cloog-0.18.1
執(zhí)行./contrib/download_prerequisites
如果編譯機器不能上網(wǎng),直接打開文本文件 download_prerequisites,把里面
依賴的庫下載回來后,放在指定目錄,然后注釋下載命令,再次執(zhí)行
contrib/download_prerequisites,把相關(guān)文件解壓,并建立鏈接。
#vi contrib/download_prerequisites
注釋 wget 相關(guān)的內(nèi)容,手動把這些文件下載回來,拷貝到工作目錄 gcc-4.9.0下。
#./contrib/download_prerequisites
3.3. 創(chuàng)建編譯目錄并編譯安裝
#mkdir ../gcc-build-4.9.0
#cd ../gcc-build-4.9.0
#../gcc-4.9.0/configure --prefix=/usr/local/gcc-4.9.0 --enable-stage1-checking=release --enable-stage1-languages=c,c++,go
#make -j 4
#make install
編譯后安裝到? /usr/local/gcc-4.9.0
3.4. 驗證安裝
#cd /usr/local/gcc-4.9.0
#./bin/gcc -v
看到版本信息
...
線程模型:posix
gcc 版本 4.9.0 (GCC)
3.5. 驗證編譯功能(C++ 2011)
構(gòu)造代碼文件 test_gcc4.9.cpp,內(nèi)容如下:
#include
#include
#include
#include
#include
using namespace std;
template T stringcat(T &x,T &y)
{
std::cout<
x += x;
y += y;
//睡眠指定毫秒數(shù)
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::cout<
return x + y;
}
template class CTheadOperator
{
public:
//采有創(chuàng)建線程發(fā)起異步調(diào)用
void createthread();
};
template void CTheadOperator::createthread()
{
std::string x = "x",y = "y";
auto b = std::bind(stringcat<:string>,x,y);
std::cout<
std::thread tp(b);
tp.join();
//注意觀察返回值的變化
std::cout<
}
int main(int argc,char *argv[])
{
CTheadOperator<:string> tp;
tp.createthread();
return 0;
}
編譯執(zhí)行,注意看參數(shù) -std=c++11,-lstdc++,證明是使用新標準
查看鏈接的動態(tài)庫,是新的庫
編譯后的文件可執(zhí)行,執(zhí)行正常
#/usr/local/gcc-4.9.0/bin/g++ -Wwrite-strings -std=c++11 test_gcc4.9.cpp -o test_gcc4.9 -I/usr/local/gcc-4.9.0/include -L/usr/local/gcc-4.9.0/lib64 -lstdc++ -fpermissive -lpthread
#ldd test_gcc4.9
linux-vdso.so.1 =>? (0x00007fff2fbff000)
libstdc++.so.6 => /usr/local/gcc-4.9.0/lib64/libstdc++.so.6 (0x00007f94ae037000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003431800000)
libm.so.6 => /lib64/libm.so.6 (0x0000003431000000)
libgcc_s.so.1 => /usr/local/gcc-4.9.0/lib64/libgcc_s.so.1 (0x00007f94ade07000)
libc.so.6 => /lib64/libc.so.6 (0x0000003430c00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003430800000
#./test_gcc4.9
createthread wait stringcat....
stringcat start....
stringcat end....
無參數(shù)被修改 x y
3.6. 驗證編譯功能(C11),缺少 threads.h文件,編譯失敗
創(chuàng)建文件test_gcc4.9.c,內(nèi)容如下:
#include
#include
//注意這行,路徑不一致
#include
//注意這個,函數(shù)定義必須是
//typedef int(*_Thrd_start_t)(void *);
int fun(void *data)
{
printf("thread=%d\n", thrd_current());
//std::map<:string std::string> m;
//m.insert(std::make_pair("a1", "b1"));
//auto result = m.insert(std::make_pair("a1", "b1"));
//if (result.second)
//{
//printf("m insert true %d,", thrd_current());
//std:std::cout << "key=" << result.first->first << ",value=" << result.first->second << endl;
//}
//else
//{
//printf("m insert fail %d\n", thrd_current());
//}
return 0;
}
int main(int argc,char *argv[])
{
thrd_t loc;
thrd_create(&loc, fun,0);
thrd_join(loc,0);
return 0;
}
編譯執(zhí)行,注意看參數(shù) -std=c11,-lgcc_s,證明是使用新標準
查看鏈接的動態(tài)庫,是新的庫
嗚呼,無法編譯成功,無法執(zhí)行正常!!!
#/usr/local/gcc-4.9.0/bin/gcc -Wwrite-strings -std=c11 test_gcc4.9.c -o test_gcc4.9 -I/usr/local/gcc-4.9.0/include -L/usr/local/gcc-4.9.0/lib64 -lgcc_s -lpthread;
#test_gcc4.9.c:4:21: 致命錯誤:threads.h:沒有那個文件或目錄
#include
^
編譯中斷。
在CentOS 6.4中編譯安裝GCC 4.8.1 + GDB 7.6.1 + Eclipse 在CentOS 6.4中編譯安裝GCC 4.8.1 + GDB 7.6.1 + Eclipse
GCC 的詳細介紹:請點這里
GCC 的下載地址:請點這里
總結(jié)
以上是生活随笔為你收集整理的linux检查是否安装proc编译器,编译安装 GCC 4.9并验证使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 没权限dev null,Li
- 下一篇: linux服务器磁盘格式,linux下查