linux下《UNIX环境高级编程》(apue2)源码编译出错的处理方法

linux下《UNIX环境高级编程》(apue2)源码编译出错的处理方法汇总 linux下《UNIX环境高级编程》(apue2)源码编译出错的处理方法 文章出处:http://www.diybl.com/course/3_program/c++/cppjs/2008617/126036.html 相信很多跟我一样想要学习unix编程的朋友在兴冲冲拿到《unix环境高级编程》后,准备拿源码练练手时,执行第一个myls就出现一大堆的 错误,这未免时个不小的打击。今天把解 阅读详情
Linux下《UNIX环境高级编程》(apue2)源码编译出错的处理方法

[url=http://www.linuxdiyf.com/bbs/viewthread.php?tid=90655][/url]

此书的源代码在http://www.apuebook.com/

相信很多跟我一样想要学习unix编程的朋友在兴冲冲拿到《unix环境高级编程》后,准
备拿源码练练手时,执行第一个myls就出现一大堆的错误,这未免时个不小的打击。今天把解决方法写下来,第一自己有个记录,第二也帮助那些被同样问题困
扰的朋友尽快的进入linux美丽的世界。(只限linux系统)
首先需要make一次源代码
编辑源码解压生成的apue.2e文件夹下的Make.defines.linux
修改WKDIR=/home/var/apue.2e为你的apue.2e目录,比如我的apue源码解压在/usr/local,那我就改为:
WKDIR=/usr/local/apue.2e
然后进入apue.2e/std 目录,编辑linux.mk。修改里面所有的nawk为awk。
最后返回apue.2e目录,执行make命令。
以下是编译源码时的错误提示跟解决方法(假定你的工作目录跟我的一样,为/usr/local/apue.2e)
错误提示1:
myls.c:1:19: apue.h: No such file or directory
myls.c: In function `main':
myls.c:13: error: `NULL' undeclared (first use in this function)
myls.c:13: error: (Each undeclared identifier is reported on ly on ce
myls.c:13: error: for each function it appears in.)
解决办法:
拷贝apue.h到系统默认头文件目录中
$cp /usr/local/apue.2e/include/apue.h /usr/include
错误提示2:
/tmp/ccBBopm0.o(.text+0x2b): In function `main':
: undefined reference to `err_quit'
/tmp/ccBBopm0.o(.text+0x5f): In function `main':
: undefined reference to `err_sys'
collect2: ld returned 1 exit status
解决办法:
err_quit跟err_sys是作者自己定义的错误处理函数,需要单独定义头文件
在/usr/include 下新建一个名为myerr.h的文件
拷贝下边的内容到myerr.h(其实此头文件在原书的附录B中)
QUOTE: #include "apue.h"
#include       /* for definition of errno */
#include      /* ISO C variable aruments */
static void err_doit(int, int, const char *, va_list);
/*
* Nonfatal error related to a system call.
* Print a message and return.
*/
void
err_ret(const char *fmt, ...)
{
    va_list     ap;
    va_start(ap, fmt);
    err_doit(1, errno, fmt, ap);
    va_end(ap);
}
/*
* Fatal error related to a system call.
* Print a message and terminate.
*/
void
err_sys(const char *fmt, ...)
{
    va_list     ap;
    va_start(ap, fmt);
    err_doit(1, errno, fmt, ap);
    va_end(ap);
    exit(1);
}
/*
* Fatal error unrelated to a system call.
* Error co de passed as explict parameter.
* Print a message and terminate.
*/
void
err_exit(int error, const char *fmt, ...)
{
    va_list     ap;
    va_start(ap, fmt);
    err_doit(1, error, fmt, ap);
    va_end(ap);
    exit(1);
}
/*
* Fatal error related to a system call.
* Print a message, dump core, and terminate.
*/
void
err_dump(const char *fmt, ...)
{
    va_list     ap;
    va_start(ap, fmt);
    err_doit(1, errno, fmt, ap);
    va_end(ap);
    abort();        /* dump core and terminate */
    exit(1);        /* shouldn't get here */
}
/*
* Nonfatal error unrelated to a system call.
* Print a message and return.
*/
void
err_msg(const char *fmt, ...)
{
    va_list     ap;
    va_start(ap, fmt);
    err_doit(0, 0, fmt, ap);
    va_end(ap);
}
/*
* Fatal error unrelated to a system call.
* Print a message and terminate.
*/
void
err_quit(const char *fmt, ...)
{
    va_list     ap;
    va_start(ap, fmt);
    err_doit(0, 0, fmt, ap);
    va_end(ap);
    exit(1);
}
/*
* Print a message and return to caller.
* Caller specifies "errnoflag".
*/
static void
err_doit(int errnoflag, int error, const char *fmt, va_list ap)
{
    char    buf[MAXLINE];
   vsnprintf(buf, MAXLINE, fmt, ap);
   if (errnoflag)
       snprintf(buf+strlen(buf), MAXLINE-strlen(buf), ": %s",
         strerror(error));
   strcat(buf, " ");
   fflush(stdout);     /* in case stdout and stderr are the same */
   fputs(buf, stderr);
   fflush(NULL);       /* flushes all stdio output streams */
}
然后在你需要使用这几种错误处理函数的程序源代码里加入
#include 

就好了。


转自http://smileyang.wang.blog.163.com/blog/static/1318695812009111010118279/?fromdm&fromSearch&isFromSearchEngine=yes

UNIX环境高级编程、UNIX网络编程(卷一)环境搭建 最近学习这两本书,在直接编译书本源程序时,出现头文件“apue.h”(UNIX环境高级编程)及“unp.h”(UNIX网络编程)错误,在这里坐下配置的笔记。 首先需要安装Linux系统。(在VirtualBox虚拟机里安装Centos6.7的Linux系统) APUE: 1、使用浏览器从http://www.apuebook.com/code3e.html下载源码src.3e.tar.gz( 阅读详情

相关推荐

图生文【学习中】

图生文:提供图像,把图像对应的信息用文本描述出来

qq_19072921的博客 1787

linux下运行《UNIX环境高级编程》的第一个程序时源码编译出错的处理方法

前几天买了《UNIX环境高级编程》这本书,想好好学习下linux的编程。谁知道看到第一个列出指定目录的内容的那个例子,其实就是shell中 ls 的内容,打好代码要运行时一直出问题。后来在网上找了挺多的解决方法,终于解决了。先把方法贴上。 先在终端里面输入 vi ls.c在里面编辑如下代码 #include "apue.h" #include int main(int

叶子一哥 9382

Unreal Engine鸿蒙移植实战:环境配置、构建流程与性能优化指南

游戏引擎移植是跨平台开发中的关键技术环节,其核心原理在于通过适配目标操作系统的底层接口和工具链,实现同一套代码在不同硬件和软件环境下的高效运行。这项技术的价值在于最大化代码复用率,降低多平台维护成本,并能让应用快速触达新兴生态系统的用户。在移动游戏和XR应用领域,随着鸿蒙HarmonyOS生态的快速发展,将成熟的商业引擎如Unreal Engine迁移至此平台,成为开发者探索新市场机会的重要路径。本文聚焦于Unreal Engine项目向鸿蒙系统的移植实践,详细解析了从环境搭建、源码适配到构建打包的全链路流

weixin_29011395的博客 410

APUE2作者提供的源码编译方法及单个源码编译的实现(转载)

Linux下APUE2源码编译出错的处理方法转自:http://blog.chinaunix.net/u1/52350/showart_426726.html最近学习Linux编程,收获真的很多。以前看都是别人或man告诉你某个命令怎么使用,但现在我才领悟到,是程序的源代码决定了全部。 linux要编程,首先需要安装gcc与其它编程工具与库文件。最简单的方法是进入图形界面的添加

mr_wenhui的专栏 981

小波变换(Wavelet Transform)原理及介绍

小波变换是一种多分辨率时频分析工具,克服了傅里叶变换无法定位时间信息的缺陷。通过可伸缩平移的母小波,它能同时捕捉信号的高频细节(短时特征)和低频轮廓(整体趋势)。其核心原理是利用不同尺度的小波基与信号进行内积运算,生成时频域系数矩阵。小波变换具有动态分辨率特性,高频部分时间精度高,低频部分频率分辨率好。主要应用包括瞬态事件检测、信号降噪、数据压缩(如JPEG2000)和压缩感知(如快速MRI)。

qq_42758052的博客 5488

从零开始构建量化价值投资多因子模型

量化价值投资多因子模型的构建目的在于通过系统性的方法,综合考虑多个影响股票价值的因素,以更准确地评估股票的投资价值,为投资者提供科学的投资决策依据。本模型的构建范围涵盖了从因子的选取、数据的处理、模型的建立到模型的评估和优化等一系列过程。通过对历史数据的分析和回测,验证模型的有效性和稳定性,进而应用于实际的投资组合管理中。本文将按照以下结构进行组织:首先介绍量化价值投资和多因子模型的相关背景知识,包括核心概念和联系;接着详细阐述核心算法原理和具体操作步骤,并给出Python代码示例;

AI天才研究院 1245

_mysql.c:44:10:fatal error:'my_config.h' file not found

注意:如果你用的是python3.x,直接去看第四个问题 遇到的第一个问题 正常来说直接执行pip安装,就是可以的,但是MySQL-python偏偏比较独特 pip install MySQL-python 报错 _mysql.c:44:10: fatal error: 'my_config.h' file not found #include "my_config.h" ...

不写代码的博客 7568

【PyTorch项目实战】图像分类与识别:手写数字识别(MNIST)、普适物体识别(CIFAR-10)

主要介绍了两个经典的实战项目:(1)基于 MNIST 数据集的手写数字识别(2)基于 CIFAR-10 数据集进行图像分类

📷 图像处理践行者 | 传统算法 · 深度学习 · 多模态 | 分享实战经验与技术洞见,探索从像素到智能的无限可能。 4401

unix环境高级编程 APUE.H最简单编译方法(第二版) Linux和Ubuntu

/******************************************************************************* *第0种-最简单实用 * *******************************************************************************/. 1.直接进入源码目录的lib目录  

mitesi的专栏 2604

DeepSeek揭秘:构建高效反洗钱智能监控系统的全流程与代码实例

在金融领域,反洗钱(AML)是一项至关重要的任务。随着金融交易的复杂性和规模不断增长,传统的手工监控方法已无法满足现代金融系统的需求。因此,开发一个智能监控系统来自动识别和报告可疑交易变得尤为重要。本文将详细介绍如何使用DeepSeek技术构建一个高效的反洗钱智能监控系统,并提供相关的代码实例。

理论都是虚的,代码才是王道。 885

通俗易懂的Harris 角点检测

点击上方“3D视觉工坊”,选择“星标”干货第一时间送达Harris 角点检测 认为特征点具有局部差异性。如何描述“特征点具有局部差异性”:以每一个点为中心,取一个窗口,窗口大小为5*5...

3D视觉工坊 1474

《unix环境高级编程》源代码编译找不到apue.h等错误的解决办法

转自:http://blog.chinaunix.net/u1/52350/showart_426726.html 最近学习Linux编程,收获真的很多。以前看都是别人或man告诉你某个命令怎么使用,但现在我才领悟到,是程序的源代码决定了全部。   linux要编程,首先需要安装gcc与其它编程工具与库文件。最简单的方法是进入图形界面的添加删除程序,选上开发工具就可以了。     1.

liuzhi1218的专栏 2828

双端之Nginx+Php结合PostgreSQL搭建Wordpress

制作的 PG4WP 分支版本,它与所有版本的 WordPress 兼容,解决了原版的一些问题。参数,确保 PostgreSQL 正在监听默认端口(通常是 5432),或者你自定义的端口。:PG4WP 插件存在缺陷和不完整的功能,可能与最新版本的 WordPress 不兼容。的插件,它允许 WordPress 使用 PostgreSQL 数据库。,如果看到 Nginx 的默认欢迎页面,说明 Nginx 已正确安装。,如果看到 Nginx 的默认欢迎页面,说明 Nginx 已正确安装。

宇宙第一小趴菜的博客 1891

编译和使用APUE的源码

APUE源码的下载:http://www.apuebook.com/src.tar.gz 1.编译源码 假设源码解压到/home/crazyboy/tmp/apue.2e.src目录下. 首先修改与自己系统对应的Make.defines.*文件,我的是linux系统,就修改Make.defines.linux文件,将里面的WKDIR修改成源码所在的目录,即这一行改成"WKDIR=

mitesi的专栏 2447

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

UNIX 高级编程 学习

相信很多跟我一样想要学习unix编程的朋友在兴冲冲拿到《unix环境高级编程》后,准备拿源码练练手时,执行第一个myls就出现一大堆的 错误,这未免时个不小的打击。今天把解决方法写下来,第一自己有个记录,第二也帮助那些被同样问题困扰的朋友尽快的进入linux美丽的世界。(只限 linux系统) 首先需要make一次源代码 编辑源码解压生成的apue.2e文件夹下的Make.defines.li

cuiyifang的专栏 969

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

unix环境高级编程-书中例子使用方法

前言: 初学《UNIX环境高级编程》,想要运行书中的例子,却不知道linux系统如何编译C程序。写下博客记录自己的学习历程以及遇到的问题。 1如何在linux上编写并运行的第一个C程序。 首先用gedit新建一个c文件 然后我们开始第一个程序hello world 保存文件后开始编译 然后开始执行 成功了!!! 2.运行unix环境高级编程书上的程序。 先在这个网站 http://www....

yuan 364

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: Android ListView最佳处理方式,ListView拖动防重复数据显示,单击响应子控件
下一篇: tomcat性能优化
程序员悟空
博客等级 码龄18年 65粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值