UNIX 网络编程 编译环境搭建出错 求解答

yao_seu 发布于 2015年10月28日 | 更新于 2015年10月30日
无人欣赏。

刚刚开始看 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
共16条回复
cnsoft 回复于 2015年10月28日

看得满眼朦胧 http://stackoverflow.com/questions/6902254/stdlib-h-no-such-file-or-directory

yao_seu 回复于 2015年10月29日

1楼 @cnsoft sorry, markdown 语法不熟悉造成的。。。

玉楼 回复于 2015年10月29日

你在unp.h这个文件中定义了这些宏,但这些都是系统头文件中有的类型,所以不让你定义。

玉楼 回复于 2015年10月29日

建议:1.学习编程从Hello world开始;2.在类UNIX环境下学习开发要学会自己一个字一个字的敲。

你对环境、语法都不熟,直接拿别人的代码编译,你能知道是代码的问题还是环境的问题?不同版本的UNIX和Linux的头文件差异较大,初学者不易掌握,还是一步一步来的好。

yao_seu 回复于 2015年10月30日

4楼 @玉楼 非常感谢您的建议

cnsoft 回复于 2015年10月30日

5楼 @yao_seu 问题解决了吗? 有没有看我给你发的链接.

yao_seu 回复于 2015年10月30日

6楼 @cnsoft 还没解决,看了你给的链接,那个上面的问题是stdlib.h. linux/time.h的问题,我看了下unp.h里面没有包含linux/time.h 所以不知道怎么办

cnsoft 回复于 2015年10月30日

@yao_seu https://github.com/hailinzeng/Unix-Network-Programming 是不是和这里的代码一样? or http://www.unpbook.com/src.html

yao_seu 回复于 2015年10月30日

8楼 @cnsoft 我从Unix-Network-Programming 官网下的(就是后面那个url对应的网站),对比了下unp.h 里面完全一样

cnsoft 回复于 2015年10月30日

./configure 之后 make 很正常貌似..

yao_seu 回复于 2015年10月30日

10楼 @cnsoft 我也觉得很奇怪,不过试了很多次都是一样的错误,不知道是不是我linux系统 库文件的问题..

cnsoft 回复于 2015年10月30日

11楼 @yao_seu 我在centos 上刚试过..

yao_seu 回复于 2015年10月30日

12楼 @cnsoft 我用的是学cs50时给的一个配置好环境的ubuntu

cnsoft 回复于 2015年10月30日

13楼 @yao_seu cs50虚拟机啊? ubuntu 刚试过也ok

cnsoft 回复于 2015年10月30日

Your personal invite link: https://koding.com/R/cnsoft @yao_seu 邀请你用这个. 随时随地玩Linux.

yao_seu 回复于 2015年10月30日

15楼 @cnsoft 这个好叼,不过速度有点慢

本帖有16个回复,因为您没有注册或者登录本站,所以,只能看到本帖的10条回复。如果想看到全部回复,请注册或者登录本站。

登录 或者 注册
相关帖子

[顶 楼]
|
|
[底 楼]
|
|
[首 页]