刚刚开始看 UNIX 网络编程的书,下载了随书的程序源码,按照 README 文件进行环境配置的时候,在第二步 make 的时候出错了,出错原因如下:(开发环境是 cs50 给的虚拟机)
jharvard@appliance (~/Downloads/unpv13e/lib): make
clang -I../lib -ggdb3 -O0 -std=c99 -Wall -Werror -D_REENTRANT -Wall -c -o connect_nonb.o connect_nonb.c
In file included from connect_nonb.c:1:
In file included from ../lib/unp.h:13:
/usr/include/i386-linux-gnu/sys/types.h:109:19: error: cannot combine with
previous 'type-name' declaration specifier
typedef __ssize_t ssize_t;
^
../lib/../config.h:311:17: note: expanded from macro 'ssize_t'
#define ssize_t int
^
In file included from connect_nonb.c:1:
In file included from ../lib/unp.h:13:
In file included from /usr/include/i386-linux-gnu/sys/types.h:146:
/usr/bin/../lib/clang/3.4/include/stddef.h:42:23: error: cannot combine with
previous 'int' declaration specifier
typedef __SIZE_TYPE__ size_t;
^
../lib/../config.h:302:25: note: expanded from macro 'size_t'
#define size_t unsigned int
^
In file included from connect_nonb.c:1:
In file included from ../lib/unp.h:13:
/usr/include/i386-linux-gnu/sys/types.h:196:1: error: cannot combine with
previous 'int' declaration specifier
__intN_t (32, __SI__);
^
/usr/include/i386-linux-gnu/sys/types.h:188:15: note: expanded from macro
'__intN_t'
typedef int int##N##_t __attribute__ ((__mode__ (MODE)))
^
<scratch space>:14:1: note: expanded from here
int32_t
^
../lib/../config.h:296:17: note: expanded from macro 'int32_t'
#define int32_t int
^
In file included from connect_nonb.c:1:
In file included from ../lib/unp.h:14:
In file included from /usr/include/i386-linux-gnu/sys/socket.h:38:
/usr/include/i386-linux-gnu/bits/socket.h:33:21: error: cannot combine with
previous 'type-name' declaration specifier
typedef __socklen_t socklen_t;
^
../lib/../config.h:305:28: note: expanded from macro 'socklen_t'
#define socklen_t unsigned int
^
In file included from connect_nonb.c:1:
In file included from ../lib/unp.h:14:
In file included from /usr/include/i386-linux-gnu/sys/socket.h:38:
/usr/include/i386-linux-gnu/bits/socket.h:33:21: error: 'type-name' cannot be
signed or unsigned
../lib/../config.h:305:19: note: expanded from macro 'socklen_t'
#define socklen_t unsigned int
^
In file included from connect_nonb.c:1:
In file included from ../lib/unp.h:25:
In file included from /usr/include/netinet/in.h:22:
In file included from /usr/bin/../lib/clang/3.4/include/stdint.h:62:
In file included from /usr/bin/../lib/gcc/i686-linux-gnu/4.8/include/stdint.h:9:
/usr/include/stdint.h:48:24: error: cannot combine with previous 'char'
declaration specifier
typedef unsigned char uint8_t;
^
../lib/../config.h:326:26: note: expanded from macro 'uint8_t'
#define uint8_t unsigned char
^
In file included from connect_nonb.c:1:
In file included from ../lib/unp.h:25:
In file included from /usr/include/netinet/in.h:22:
In file included from /usr/bin/../lib/clang/3.4/include/stdint.h:62:
In file included from /usr/bin/../lib/gcc/i686-linux-gnu/4.8/include/stdint.h:9:
/usr/include/stdint.h:51:23: error: cannot combine with previous 'int'
declaration specifier
typedef unsigned int uint32_t;
^
../lib/../config.h:323:27: note: expanded from macro 'uint32_t'
#define uint32_t unsigned int
^
In file included from connect_nonb.c:1:
../lib/unp.h:227:8: error: redefinition of 'sockaddr_storage'
struct sockaddr_storage {
^
/usr/include/i386-linux-gnu/bits/socket.h:162:8: note: previous definition is
here
struct sockaddr_storage
^
In file included from connect_nonb.c:1:
../lib/unp.h:263:8: error: redefinition of 'timespec'
struct timespec {
^
/usr/include/time.h:120:8: note: previous definition is here
struct timespec
^
In file included from connect_nonb.c:1:
../lib/unp.h:286:1: error: unknown type name 'u_char'
u_char *inet_srcrt_init(int);
^
../lib/unp.h:287:24: error: unknown type name 'u_char'
void inet_srcrt_print(u_char *, int);
^
../lib/unp.h:458:21: error: type specifier missing, defaults to 'int'
[-Werror,-Wimplicit-int]
void Sysctl(int *, u_int, void *, size_t *, void *, size_t);
^~~~~
12 errors generated.
make: *** [connect_nonb.o] Error 1
看得满眼朦胧 http://stackoverflow.com/questions/6902254/stdlib-h-no-such-file-or-directory
建议:1.学习编程从Hello world开始;2.在类UNIX环境下学习开发要学会自己一个字一个字的敲。
你对环境、语法都不熟,直接拿别人的代码编译,你能知道是代码的问题还是环境的问题?不同版本的UNIX和Linux的头文件差异较大,初学者不易掌握,还是一步一步来的好。