Skip to content Skip to main navigation Skip to footer

CentOS 7/RHEL 7: 如何安装GCC编译器和开发工具

在CentOS 7和RHEL 7系统上如何安装Gnu GCC编译器和相关的工具比如:autoconf,automake,flex, c++编译器等工具。我们可以通过在centos 或者rhel 7 系统上安装下面的软件包来搭建基本的开发环境。
[cc lang=”php”] autoconf
automake
binutils
bison
flex
gcc
gcc-c++
gettext
libtool
make
patch
pkgconfig
redhat-rpm-config
rpm-build
rpm-sign
[/code] 显示当前系统的yum group,使用下面的命令:
[cc lang=”php”] yum group list
[/code] 命令输出:
[cc lang=”php”] [root@itsprite /]# yum group list
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.btte.net
* updates: mirrors.btte.net
Available environment groups:
Minimal Install
Infrastructure Server
File and Print Server
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Available Groups:
Compatibility Libraries
Console Internet Tools
Development Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
Done
[/code] 安装GCC和开发环境
输入下面的命令:
[cc lang=”php”] yum group install “Development Tools”
[/code] 安装完之后,使用下面的命令来验证gcc是否安装成功:
[cc lang=”php”] whereis gcc
[/code] 命令输出:
[cc lang=”php”] [root@itsprite /]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
[/code] 输入下面的命令来查看gcc工具的版本:
[cc lang=”php”] [root@itsprite /]# gcc –version
gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[/code] 测试GCC编译器
下面我们使用刚安装好的GCC编译器来编译一个c语言程序.
创建下面的test.c程序:
[cc lang=”c”] #include
int main(void){
printf(“Hello World!\n”);
return 0;
}
[/code] 输入命令编译test.c 文件:
[cc lang=”php”] gcc test.c -o test
[/code] 执行编译后的文件:
[cc lang=”php”] ./test
Hello World!
[/code]

0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.