日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UNIX网络编程 卷2 源代码使用

發(fā)布時間:2023/12/2 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UNIX网络编程 卷2 源代码使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1. 下載源碼,W. Richard Stevens的主頁:http://www.kohala.com/start/ wget http://www.kohala.com/start/unpv22e/unpv22e.tar.gz -P /usr/local/src? 2. 解壓 tar xvf /usr/local/src/unpv22e.tar.gz -C /root/bin? 3. 編譯庫文件 cd /root/bin/unpv22e/ ? ./configure? 編輯生成config.h文件,注釋以下幾行 vi config.h ? 56 // #define uint8_t unsigned char ? 57 // #define uint16_t unsigned short ? 58 // #define uint32_t unsigned int ? 添加MSG_R和MSG_W定義 vi config.h ? 66 // add by jcq ? 67 typedef unsigned long ulong_t; ? 68 #define MSG_R 0400 ? 69 #define MSG_W 0200? 添加_GNU_SOURCE定義 vi config.h ? #define _GNU_SOURCE? 修改warpunix.c中的MKtemp函數(shù),使用mkstemp函數(shù)替換mktemp函數(shù) cd lib ? 181 void ? 182 Mktemp(char *template) ? 183 { ? 184 if (mkstemp(template) == NULL || template[0] == 0) ? 185 err_quit("mktemp error"); ? 186 }? 編譯生成libunpipc.a cd lib ? make 將生成的libunpipc.a復(fù)制到/usr/lib中。 [root@localhost myunp2]# vim ftok.c [root@localhost myunp2]# gcc -o ftok ftok.c /tmp/ccxRydhw.o: In function `main': ftok.c:(.text+0x18): undefined reference to `err_quit' ftok.c:(.text+0x30): undefined reference to `Stat' ftok.c:(.text+0x48): undefined reference to `Ftok' collect2: 錯誤:ld 返回 1 [root@localhost myunp2]# gcc -o ftok ftok.c -lunpipc /usr/lib/libunpipc.a(wrapunix.o): In function `Mq_open': wrapunix.c:(.text+0x4d8): undefined reference to `mq_open' wrapunix.c:(.text+0x4f0): undefined reference to `mq_open' /usr/lib/libunpipc.a(wrapunix.o): In function `Mq_close': wrapunix.c:(.text+0x52b): undefined reference to `mq_close' /usr/lib/libunpipc.a(wrapunix.o): In function `Mq_unlink': wrapunix.c:(.text+0x55b): undefined reference to `mq_unlink' /usr/lib/libunpipc.a(wrapunix.o): In function `Mq_send': wrapunix.c:(.text+0x5a3): undefined reference to `mq_send' /usr/lib/libunpipc.a(wrapunix.o): In function `Mq_receive': wrapunix.c:(.text+0x5e3): undefined reference to `mq_receive' /usr/lib/libunpipc.a(wrapunix.o): In function `Mq_notify': wrapunix.c:(.text+0x623): undefined reference to `mq_notify' /usr/lib/libunpipc.a(wrapunix.o): In function `Mq_getattr': wrapunix.c:(.text+0x653): undefined reference to `mq_getattr' /usr/lib/libunpipc.a(wrapunix.o): In function `Mq_setattr': wrapunix.c:(.text+0x68b): undefined reference to `mq_setattr' /usr/lib/libunpipc.a(wrapunix.o): In function `Sem_open': wrapunix.c:(.text+0x9c8): undefined reference to `sem_open' wrapunix.c:(.text+0x9e0): undefined reference to `sem_open' /usr/lib/libunpipc.a(wrapunix.o): In function `Sem_close': wrapunix.c:(.text+0xa1b): undefined reference to `sem_close' /usr/lib/libunpipc.a(wrapunix.o): In function `Sem_unlink': wrapunix.c:(.text+0xa4b): undefined reference to `sem_unlink' /usr/lib/libunpipc.a(wrapunix.o): In function `Sem_init': wrapunix.c:(.text+0xa8b): undefined reference to `sem_init' /usr/lib/libunpipc.a(wrapunix.o): In function `Sem_destroy': wrapunix.c:(.text+0xabb): undefined reference to `sem_destroy' /usr/lib/libunpipc.a(wrapunix.o): In function `Sem_wait': wrapunix.c:(.text+0xaeb): undefined reference to `sem_wait' /usr/lib/libunpipc.a(wrapunix.o): In function `Sem_trywait': wrapunix.c:(.text+0xb1c): undefined reference to `sem_trywait' /usr/lib/libunpipc.a(wrapunix.o): In function `Sem_post': wrapunix.c:(.text+0xb5b): undefined reference to `sem_post' /usr/lib/libunpipc.a(wrapunix.o): In function `Sem_getvalue': wrapunix.c:(.text+0xb93): undefined reference to `sem_getvalue' /usr/lib/libunpipc.a(wrapunix.o): In function `Shm_open': wrapunix.c:(.text+0xccc): undefined reference to `shm_open' /usr/lib/libunpipc.a(wrapunix.o): In function `Shm_unlink': wrapunix.c:(.text+0xd0b): undefined reference to `shm_unlink' collect2: 錯誤:ld 返回 1 [root@localhost myunp2]# gcc -lrt -o ftok ftok.c -lunpipc [root@localhost myunp2]# man mq_open Cannot open the message catalog "man" for locale "zh_CN.UTF-8" (NLSPATH="/usr/share/locale/%l/LC_MESSAGES/%N")Formatting page, please wait...

出現(xiàn)上面的錯誤,使用gcc 加選項-lrt解決。

?

錯誤:

[root@localhost myunp2]# gcc -lrt -o slot slot.c -lunpipc slot.c: 在函數(shù)‘main’中: slot.c:8:22: 錯誤:‘IPC_PRIVATE’未聲明(在此函數(shù)內(nèi)第一次使用)msqid=Msgget(IPC_PRIVATE,SVMSG_MODE|IPC_CREAT);^ slot.c:8:22: 附注:每個未聲明的標識符在其出現(xiàn)的函數(shù)內(nèi)只報告一次 In file included from slot.c:1:0: unpipc.h:153:21: 錯誤:‘MSG_R’未聲明(在此函數(shù)內(nèi)第一次使用)#define SVMSG_MODE (MSG_R | MSG_W | MSG_R>>3 | MSG_R>>6)^ slot.c:8:34: 附注:in expansion of macro ‘SVMSG_MODE’msqid=Msgget(IPC_PRIVATE,SVMSG_MODE|IPC_CREAT);^ unpipc.h:153:29: 錯誤:‘MSG_W’未聲明(在此函數(shù)內(nèi)第一次使用)#define SVMSG_MODE (MSG_R | MSG_W | MSG_R>>3 | MSG_R>>6)^ slot.c:8:34: 附注:in expansion of macro ‘SVMSG_MODE’msqid=Msgget(IPC_PRIVATE,SVMSG_MODE|IPC_CREAT);^ slot.c:8:45: 錯誤:‘IPC_CREAT’未聲明(在此函數(shù)內(nèi)第一次使用)msqid=Msgget(IPC_PRIVATE,SVMSG_MODE|IPC_CREAT);^ slot.c:11:22: 錯誤:‘IPC_RMID’未聲明(在此函數(shù)內(nèi)第一次使用)Msgctl(msqid,IPC_RMID,NULL);

解決方法:

1.unpv22e里面的Make.defines?
修改?
#CFLAGS = -g -O2 -D_REENTRANT -Wall?
CFLAGS = -g -O2 -D_GNU_SOURCE -D__USE_GNU -D_REENTRANT -Wall?

2 將unpv22e中的unpipc.h拷貝到需要編譯的代碼的目錄。

3 將config.h也拷貝到這個目錄,由于unpipc.h依賴于這個頭文件。

總結(jié)

以上是生活随笔為你收集整理的UNIX网络编程 卷2 源代码使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。