Chinaunix首页 | 论坛 | 博客
  • 博客访问: 98360
  • 博文数量: 22
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 0
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-17 11:22
文章分类

全部博文(22)

文章存档

2015年(6)

2014年(16)

我的朋友

分类: LINUX

2015-01-09 11:18:54

原文地址:unix 环境高级编程-1 作者:leolzbing521

linux man:

1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
n 新文档, 可能要移到更适合的领域。
o 老文档, 可能会在一段期限内保留。
l 本地文档, 与本特定系统有关的。

1. 第一个程序

 gcc 1.1.c 
/tmp/ccbnJqcB.o: In function `main':
1.1.c:(.text+0x17): undefined reference to `err_quit'
1.1.c:(.text+0x4a): undefined reference to `err_sys'
collect2: ld returned 1 exit status

原来需要到在下载src.2e.tar.gz源代码的压缩包,首先查看readme,需要更改Make.defines.linux中的WKDIR为实际存储该源代码目录的路径。

在apue.2e目录下执行make,有

/usr/include/i386-linux-gnu/bits/timex.h:31:7: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘.’ token

原因:
在apue.2e/ipp.h中定义了一个宏定义status和/usr/include/i386-linux-gnu/bits/timex.h中的成员status冲突
解决方法:
修改这个apue.2e/ipp/ipp.h文件中的宏名称,例如改为Status
然后将apue.2e/ipp/printd.c中977行的 hp->status 改为hp->Status


重新make后第一个问题解决了,出现第二个问题
getenv1.c:4:20: error: ‘ARG_MAX’ undeclared here (not in a function)
在apue.2e/include/apue.h中添加一行:
#define ARG_MAX 4096
打开apue.2e/threadctl/getenv1.c 和apue.2e/threadctl/getenv3.c,添加一行:
#include "apue.h"

编译通过。

下面我们把apue的头文件和库文件放入系统:

把头文件apue.h放到/usr/include/中,注意要以root用户操作以下命令
cp ~/apue.2e/include/apue.h /usr/include
cp ~/apue.2e/lib/libapue.a /usr/lib/


编译运行程序
gcc  源程序.c -o 可执行程序名 -lapue

注意 :若-lapue 写在了源程序的前面会出现错误 eg. gcc ls1.c -o ls1 -lapue
因为
.a在链接的时候,必须放在文件之后
.so在链接的时候,对位置没有要求,前后都可以

http://blog.csdn.net/libinjlu/article/details/9473239
http://blog.csdn.net/ce_endless/article/details/6885708

阅读(1430) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~