2013-03-25 62 views
1

我正在使用Linux Mint 13,並且正在研究「Unix網絡編程:進程間通信」一書。我下載了本書的源代碼 - http://www.kohala.com/start/unpv22e/unpv22e.html - 並按照說明操作。無法構建「Unix網絡編程:進程間通信」的源代碼

首先,我跑在基本目錄

然後,我去到lib目錄並運行做出的./configure。這提供了以下錯誤 -

gcc -c "/home/linux/Code/c/unix_network_programming/main.c" -g -o ./Debug/main.o "-I." "-I." 
In file included from /usr/lib/gcc/i686-linux-gnu/4.6/include/stdint.h:3:0, 
       from /usr/include/netinet/in.h:24, 
       from /usr/include/rpc/types.h:91, 
       from /usr/include/rpc/rpc.h:38, 
       from /home/linux/Code/c/unix_network_programming/unpipc.h:115, 
       from /home/linux/Code/c/unix_network_programming/main.c:2: 
/usr/include/stdint.h:49:24: error: duplicate ‘unsigned’ 
/usr/include/stdint.h:49:24: error: two or more data types in declaration specifiers 
/usr/include/stdint.h:50:28: error: duplicate ‘unsigned’ 
/usr/include/stdint.h:50:28: error: duplicate ‘short’ 
/usr/include/stdint.h:52:23: error: duplicate ‘unsigned’ 
/usr/include/stdint.h:52:23: error: two or more data types in declaration specifiers 

下面是是給錯誤的文件 -

#ifndef _GCC_WRAP_STDINT_H 
#if __STDC_HOSTED__ 
# include_next <stdint.h> 
#else 
# include "stdint-gcc.h" 
#endif 
#define _GCC_WRAP_STDINT_H 
#endif 

如何爲我很少ç經驗修正此錯誤任何想法?

+0

你可以運行'autoconf'來重建configure腳本。 – pce 2013-03-25 17:20:36

+0

Yuck yuck yuck!問題出在AC_UNP_CHECK_TYPE中,這是一個令人不快的宏。問題在於代碼是針對沒有stdint.h的略舊的系統編寫的,系統的netinet頭文件中包含stdint.h。糟糕的是,AC_UNP_CHECK_TYPE做了一個「#define uint8_t unsigned char」而不是使用typedef,所以當真正的uint8_t被髮揮時,所有東西都會爆炸。 – 2013-03-25 17:30:44

+0

是否可以從書中的unpipc.h試圖定義stdint中定義的某些類型? – Digikata 2013-03-25 17:33:08

回答

1

應用以下,輕度討厭的補丁:

diff -U 3 ./aclocal.m4 ./aclocal.m4 
--- ./aclocal.m4  1997-10-10 22:45:46.000000000 +0100 
+++ ./aclocal.m4  2013-03-25 17:35:22.287397177 +0000 
@@ -31,6 +31,7 @@ 
       AC_TRY_COMPILE(
[ 
#include  "confdefs.h" /* the header built by configure so far */ 
+#include <stdint.h> 
#ifdef HAVE_SYS_TYPES_H 
# include  <sys/types.h> 
#endif 
diff -U 3 ../unpv22e/config.h.in ./config.h.in 
--- ./config.h.in  1998-06-10 18:26:41.000000000 +0100 
+++ ./config.h.in  2013-03-25 17:42:18.788139903 +0000 
@@ -2,6 +2,7 @@ 
#undef CPU_VENDOR_OS 

/* *INDENT-OFF* */ 
+#undef HAVE_STDINT_H 
#undef HAVE_DOOR_H        /* <door.h> */ 
#undef HAVE_MQUEUE_H       /* <mqueue.h> */ 
#undef HAVE_POLL_H        /* <poll.h> */ 
@@ -49,6 +50,9 @@ 
#undef HAVE_DEV_ZERO 

/* Define the following to the appropriate datatype, if necessary */ 
+#ifdef HAVE_STDINT_H 
+#include <stdint.h> 
+#endif 
#undef int8_t       /* <sys/types.h> */ 
#undef int16_t       /* <sys/types.h> */ 
#undef int32_t       /* <sys/types.h> */ 
diff -U 3 ../unpv22e/configure.in ./configure.in 
--- ./configure.in  1998-06-06 22:42:29.000000000 +0100 
+++ ./configure.in  2013-03-25 17:38:14.555324559 +0000 
@@ -105,7 +105,7 @@ 
dnl but used in "lib/wrapunix.c". 
dnl 
AC_HEADER_STDC 
-AC_CHECK_HEADERS(sys/types.h sys/time.h time.h errno.h fcntl.h limits.h signal.h stdio.h stdlib.h string.h sys/stat.h unistd.h sys/wait.h sys/ipc.h sys/msg.h sys/sem.h sys/shm.h mqueue.h semaphore.h sys/mman.h sys/select.h poll.h stropts.h strings.h sys/ioctl.h sys/filio.h pthread.h door.h rpc/rpc.h sys/sysctl.h) 
+AC_CHECK_HEADERS(stdint.h sys/types.h sys/time.h time.h errno.h fcntl.h limits.h signal.h stdio.h stdlib.h string.h sys/stat.h unistd.h sys/wait.h sys/ipc.h sys/msg.h sys/sem.h sys/shm.h mqueue.h semaphore.h sys/mman.h sys/select.h poll.h stropts.h strings.h sys/ioctl.h sys/filio.h pthread.h door.h rpc/rpc.h sys/sysctl.h) 

dnl ################################################################## 
dnl Checks for typedefs. 

然後運行autoconf的(使用autoconf2.13而不是更新的版本),刪除config.cache的,然後再試一次。

+0

我將你的文字保存爲'mypatch'。然後我在src目錄中運行patch -p1 csss 2013-03-25 17:55:24

+0

*%$ ^本書可能已經這是二十年前的經典之作,但我不能爲這個垃圾處理而煩惱,我會得到一本Linux特定的書。 – csss 2013-03-25 19:09:34

+0

不不不不!這仍然是一個經典!我是一位經驗豐富的商業開發人員,閱讀過一遍又一遍的封面,我可以說,它有它的弱點,但是太棒了。您正在使用較舊的音量(vol1的第三版,有用音量,更現代)。無論你選擇哪本書,無論如何你都不應該屈服於linux單一文化。 – 2013-03-25 22:21:17

1

註釋掉這些行的config.h(執行./configure在前):

#define uint8_t unsigned char   /* <sys/types.h> */ 
#define uint16_t unsigned short  /* <sys/types.h> */ 
#define uint32_t unsigned int   /* <sys/types.h> */ 

它爲我:)。