編譯APUE附帶源碼

來源:互聯網
上載者:User

編譯APUE附帶源碼

之前寫的關於建立靜態庫的方法直接使用書中代碼的方法http://hi.baidu.com/logicbaby/blog/item/3dc21fdb4ce75b60d0164e4e.html,

今天仔細看了下源碼包檔案夾下的README檔案,才知道不用這麼麻煩,那源碼包是可以直接安裝的,但是都是建立靜態庫的方法啦。

To build the source, edit the Make.defines.* file for your system and set
WKDIR to the pathname of the tree containing the source code. Then just
run "make". It should figure out the system type and build the source for
that platform automatically. If you are running on a system other than
FreeBSD, Linux, Mac OS X, or Solaris, you'll need to modify the makefiles
to include the settings for your system. Also, you'll probably need to
modify the source code to get it to build on a different operating system.
The example source was compiled and tested using FreeBSD 5.2.1, Linux 2.4.22,
Mac OS X 10.3, and Solaris 9.

1、從http://www.apuebook.com/下載Source Code

2、解壓後看到檔案夾下有好幾個類似Make.defines.*的檔案Make.defines.macos ,Make.defines.solaris
,Make.defines.linux,Make.defines.freebsd,如果不是FreeBSD, Linux ,Mac OS X , Solaris的就得自己配置了,如果是FreeBSD系統則修改Make.defines.freebsd,修改WKDIR為apue.2e所在的檔案夾,比如我的為WKDIR=/home/clooo/apue.2e。

3、在apue.2e檔案夾下直接運行make即可,其實通過Makefile發現,首先運行systype.sh判斷系統的類別,然後再編譯,將書中要用到的函數編譯成一個靜態庫apue.2e/lib/libapue.a。

4、測試

clooo@~% uname -a
FreeBSD logicbaby.localdomain 6.3-RELEASE FreeBSD 6.3-RELEASE #0: Wed Jan 16 04:45:45 UTC 2008     root@dessler.cse.buffalo.edu:/usr/obj/usr/src/sys/SMP i386

clooo@~/apue.2e% cp fig1.3 fig1.3.c
將fig1.3.c第一行改為
#include "include/apue.h"
clooo@~/apue.2e% cc fig1.3.c lib/libapue.a
clooo@~/apue.2e% ./a.out ~
.
..
.cshrc
.login
.mail_aliases
.login_conf
.rhosts
.mailrc
.profile
.shrc
apue.2e
src.tar.gz
.history
clooo@~/apue.2e%

後記:

1、我同時使用FreeBSD 6.3和Debian 4 , Debian下的方法相同,只是在第一步的時候修改的是Make.defines.linux檔案中的WKDIR

2、apue.2e在FreeBSD 7.0下編譯出錯,提示pracct.c中的acct結構體未定義,查看/usr/include/sys
下的acct.h發現有acctv1和acctv2,將acct改為acctv2即可。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.