首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

UNIX高级环境编程——搭建Linux环境

# UNIX高级环境编程——搭建Linux环境

## 安装Linux操作系统

我们用的是从搬瓦工网站(http://banwagong.cn/ )上购买的主机。

由于是购买的Linux主机,我们需要先确定Linux操作系统的类型。

```

[root@host ~]# more /etc/issue

CentOS release 6.8 (Final)

Kernel \r on an \m

```

## 搭建环境

### 创建新用户 furnace

```

[root@host ~]# adduser furnace

[root@host ~]# passwd furnace

Changing password for user furnace.

New password:

```

### 给用户 furnace 添加 root 权限

1. 给文件 /etc/sudoers 添加写权限。

```

[root@host ~]# chmod u+w /etc/sudoers

```

2. 编辑文件

```

[root@host ~]# vi /etc/sudoers

## Allow root to run any commands anywhere

root ALL=(ALL) ALL

furnace ALL=(ALL) ALL (新增)

```

3. 撤销文件 /etc/sudoers 的写权限

```

[root@host ~]# chmod u-w /etc/sudoers

```

### 安装必要的软件

1. 安装 vim

```

[root@host ~]# yum install vim

```

2. 安装 gcc

```

[root@host ~]# yum install gcc

[root@host ~]# gcc --version

gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)

Copyright (C) 2010 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.

```

3. 安装 make

```

[root@host ~]# yum install make

[root@host ~]# make --version

GNU Make 3.81

Copyright (C) 2006 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.

This program built for i386-redhat-linux-gnu

```

4. 安装 tar

```

[root@host ~]# yum install tar

```

## 下载源代码

```

[furnace@host apue]$ ls

```

## 编译源代码

查看文件 README。直接运行 make 进行完整构建。之后执行目录 intro 中的文件 hello 验证编译是否完成。

在编译过程中会遇到一些问题,提示某些文件编译失败,只需要特定的处理一下就可以,并不会影响到整个编译都失败。第一次可以忽略,后面再解决。

```

[furnace@host apue]$ cd apue.3e/

[furnace@host apue.3e]$ make

[furnace@host apue.3e]$ cd intro/

[furnace@host intro]$ ./hello

hello world from process ID 11428

```

至此,完成了 "Unix Network Programming, Volume 1: The Sockets Networking API (Third Edition)" 中的源代码运行环境的搭建,以及编译源代码的完整流程。后面可以实战相应的实例了。

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20180618G02ZWJ00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券