C++ primer (5th) 随想与学习笔记 2 怎样在Linux上安装GCC

Notice:不知问什么,我文中的url被禁止发布不了,只好都删去了,希望CSDN想想办法解决吧!

deny

1.1 编写一个简单的C++程序

C++程序是通过main函数才能进入的,这点在编译性的语言上(C,C++)都是这样,不像脚本语言(Matlab、Python)那么自由。函数的定义包含4个部分:返回类型、函数名、形参列表以及函数体。C++有自身内置(built-in)的类型,可以参考C语言数据类型。末尾的分号表示一条语句执行完毕,return直接表示这个函数体执行完毕,不论return内嵌多深,都要跳出当前函数体。main函数的返回值对系统有指示作用,0表示成功,其余的表示异常。

1.1.1 编译、执行和程序

建议初学者用命令行模式,先别忙着用IDE(Integrated Developed Environment,集成开发环境),如Visio C++/studio。

学习一下GNU编译器:

GNU GCC是GNU开发的一个编译器套件集(GNU不是公司名,而是一个有约40年历史的软件项目名)。GCC全称GNU Compiler Collection,包括多种编程语言的编译器。这些编译器作为一个整体,被称为GCC,它不是IDE。

我的电脑是Liunx Centos6.4 服务器64wei版本,没装gcc

<span style="font-size:14px;">$ rpm -qa | grep gcc</span>

本来电脑是局域网没连外网,我也不想用

<span style="font-size:14px;">$ yum -install gcc</span>

但我也没想从source code编起,逼近没有gcc怎么编译啊?我就是想乘机学习一下rpm是怎么工作法、流程是什么。不想这里面学问也大的很,不信就听我慢慢道来:

<span style="font-size:14px;">$ rpm -ivh gcc-*</span>

哇!这命令一执行一大堆依赖文件:
<pre name="code" class="plain"><span style="font-size:14px;">error failed:
    clooq-ppl
    glibc-devel
    cpp
    各种libc.so</span>
 

如果在深入到这些包里面又是各个依赖包,既然已经做了就跟到底好了。先来看看cpp包

<span style="font-size:14px;">$ rpm -ivh cpp</span>

cpp底层还有个mpfr依赖包:

GNU MPFR is a portable C library for arbitrary-precision binary floating-point computation with correct rounding, based on GNU Multi-Precision Library

mpfr是给浮点数提供任意精度的C包,参考http://www.mpfr.org/。下载Centos6.4 mpfr

回到cpp,cpp是C编译预处理,下载Centos6.4 mpfr:

The C Preprocessor.
Description : 
Cpp is the GNU C-Compatible Compiler Preprocessor.
Cpp is a macro processor which is used automatically
by the C compiler to transform your program before actual
compilation. It is called a macro processor because it allows
you to define macros, abbreviations for longer
constructs.
The C preprocessor provides four separate functionalities: the
inclusion of header files (files of declarations that can be
substituted into your program); macro expansion (you can define macros,
and the C preprocessor will replace the macros with their definitions
throughout the program); conditional compilation (using special
preprocessing directives, you can include or exclude parts of the
program according to various conditions); and line control (if you use
a program to combine or rearrange source files into an intermediate
file which is then compiled, you can use line control to inform the
compiler about where each source line originated).
You should install this package if you are a C programmer and you use
macros.

这时

<span style="font-size:14px;">$rpm -ivh mpfr*
$rpm -ivh cpp*</span>
就没问题了,说明已经装好了,还有两个包clooq-ppl和glib-devel,我也是这样一步一步来的:

clooq包很简单除了PPL外没别的依赖包,PPL是用于数据抽象的,比如多面体。下载Centos6.4_X64 PPL

而clooq包就是PPL的动态链接库,下载Centos6.4_X64 CLOOQ

Summary : The Parma Polyhedra Library: a library of numerical abstractions
Description : 
The Parma Polyhedra Library (PPL) is a library for the manipulation of
(not necessarily closed) convex polyhedra and other numerical
abstractions. The applications of convex polyhedra include program
analysis, optimized compilation, integer and combinatorial
optimization and statistical data-editing. The Parma Polyhedra
Library comes with several user friendly interfaces, is fully dynamic
(available virtual memory is the only limitation to the dimension of
anything), written in accordance to all the applicable standards,
exception-safe, rather efficient, thoroughly documented, and free
software. This package provides all what is necessary to run
applications using the PPL through its C and C++ interfaces.
glib_devel是依赖包最多的,有glibc-headers、glibc、glibc-common以及kernel-header,安装的顺序应该为

<span style="font-size:14px;">$rpm -<span style="color:#ff0000;">F</span>vh glib* glib-common*
$rpm -ivh kernal-header*
$rpm -ivh glib-header*</span>
这里安装glib和glib-common需要注意一下,由于这两者是circular dependency关系,只有一起安装才可以,我使用了rpm -F,

可以参考这里

包名作用
glib-header标准C语言库的头文件
glibGNU函数库
glib-commonGNU公用库,包括二进制、环境参量等
kernel-headerliunx内核拓展来的头文件

这些包装好了就可以安装glib-devel了:

<span style="font-size:14px;">$rpm -ivh glib-devel*</span>

glib-devel是C语言函数库的对象文件,下载Centos6.4_64glib-devel。
走到这里算作完成了90%了,但下面还有几个细节需要把握

由于libgcc和libgnome是Liunx自带的但是版本很低需要更新,下载Centos6.4_64libgcc、libgomp,然后执行

<span style="font-size:14px;">$rpm -Uvh libgcc*
$rpm -Uvh libgomp*</span>
-U表示更新的意思,完成最后一步:

<span style="font-size:14px;">$rpm -ivh gcc*</span>

测试一下

<span style="font-size:14px;">$gcc -v</span>

没问题就是成功了!!!!!

这就算做第二遍吧,今天不想写了,晚饭还没吃。只是写给自己看的,以后可能还能用到,先练练手笔!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值