zoukankan      html  css  js  c++  java
  • Linux安装apue.3e(基于ubuntu16.0.4)

    本菜刚刚学习UNIX高级编程,无奈搭建本书编程环境时遇到不少问题,参考了网上各路大神的解决办法,最终解决了问题。

    (1)下载源代码,可以去官网下载:http://apuebook.com/code3e.html

    (2)解压缩源代码文件:tar -zxvf src.3e.tar.gz

    (3) 安装静态链接库:sudo apt-get install libbsd-dev  

    (4) make

    (5).在编译成功的基础上,我们进行安装apue.h文件及其对应的静态链接库libapue.a

         sudo cp ./include/apue.h /usr/include/
         sudo cp ./lib/libapue.a /usr/local/lib/
    为什么要将libapue.a移到/usr/local/lib中呢?原因是libapue.a是apue.h头文件中包含的所有函数及宏定义的具体实现,是一个静态链接库。

    (6)创建apueerror.h文件

    /**************
     *
     *apueerror.h
     *
     *************/
    #include <apue.h>
    #include <stdio.h>
    #include <errno.h> /* for definition of errno */
     
    #include <stdarg.h> /* 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 code 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 */
    }

    (7)sudo cp apueerror.h  /usr/include/

    (8)在要编译运行的代码中#include<apue.h>的下一行增加一行:#include <apueerror.h>

    (9)编译就完事了

  • 相关阅读:
    php之工厂模式
    PHP 给GIF 缩略图实例代码
    WGS84 Mercator project转换的算法(C#)
    .net Enum用法
    Google Maps API编程资源大全
    结对作业
    使用Lightbox制作照片条
    使用css3中transition的页面切换
    使用css3中transition的页面切换(继续创新版)
    iframe中父窗口获取子窗口的元素
  • 原文地址:https://www.cnblogs.com/lesroad/p/9738020.html
Copyright © 2011-2022 走看看