2022-04-11 11:23阅读: 206评论: 0推荐: 0

Mac OS配置APUE(Unix环境高级编程)环境

最近在温习APUE(《unix环境高级编程》),以前都是在linux下搞,现在打算在自己机器弄下,于是google了下,把编译的事情搞定了,修改了一些教程的一些错误,比如下载链接之类的。

  1. 下载源文件
wget http://www.apuebook.com/src.3e.tar.gz
  1. 解压
tar -zxf src.3e.tar.gz
  1. 编译
cd apue.3e && make all
  1. 复制头文件
cp ./include/apue.h /usr/local/include/
cp ./lib/error.c /usr/local/include/
cp ./lib/libapue.a /usr/local/lib
  1. 修改apue.h
vim /usr/local/include/apue.h
# 按`shift + G`跳转至最后一行,在 #end if 之前插入
#include "error.c"
  1. 测试一下
//test.c
#include "apue.h"
#include <dirent.h>
int main(int argc, char *argv[]) {
DIR *dp;
struct dirent *dirp;
if (argc != 2) {
err_quit("usage:ls directory_name");
}
if ((dp = opendir(argv[1])) == NULL) {
err_sys("can't open %s", argv[1]);
}
while ((dirp = readdir(dp)) != NULL) {
printf("%s\n", dirp->d_name);
}
closedir(dp);
exit(0);
}

编译时制定链接库文件-lapue

gcc test.c -lapue -o test
./test
usage:ls directory_name

另见 Homebrew进阶使用教程(三)-apue.h在mac下安装并使用连接

posted @   Tsunho12  阅读(206)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
🔑
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.