我正在尝试做一些原始的套接字编程。我有一些示例代码可以在32位机器上很好地编译/运行,但是当我尝试在64位机器上编译相同的代码时,我得到了/usr/includes/sys和/usr/includes/linux头文件之间的差异。我本以为在64位机器上,所有的头文件都已经针对64位的用法进行了“校正”。有人能给我一些关于如何解决这个问题的建议吗?我用的是linux(fedora 9 64位),GCC 4.3.2
谢谢!
我编译如下: gcc -Wall -o服务器server.c,得到以下错误:
In file included from /usr/include/sys/uio.h:24,
from /usr/include/sys/socket.h:28,
from server.c:4:
/usr/include/sys/types.h:46: error: conflicting types for ‘loff_t’
/usr/include/linux/types.h:30: error: previous declaration of ‘loff_t’ was here
/usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’
/usr/include/linux/types.h:13: error: previous declaration of ‘dev_t’ was here
In file included from /usr/include/sys/types.h:133,
from /usr/include/sys/uio.h:24,
from /usr/include/sys/socket.h:28,
from server.c:4:
/usr/include/time.h:105: error: conflicting types for ‘timer_t’
/usr/include/linux/types.h:22: error: previous declaration of ‘timer_t’ was here
In file included from /usr/include/sys/uio.h:24,
from /usr/include/sys/socket.h:28,
from server.c:4:
/usr/include/sys/types.h:198: error: conflicting types for ‘int64_t’
/usr/include/linux/types.h:98: error: previous declaration of ‘int64_t’ was here
/usr/include/sys/types.h:204: error: conflicting types for ‘u_int64_t’
/usr/include/linux/types.h:97: error: previous declaration of ‘u_int64_t’ was here
In file included from /usr/include/sys/types.h:220,
from /usr/include/sys/uio.h:24,
from /usr/include/sys/socket.h:28,
from server.c:4:
/usr/include/sys/select.h:78: error: conflicting types for ‘fd_set’
/usr/include/linux/types.h:12: error: previous declaration of ‘fd_set’ was here
In file included from /usr/include/sys/uio.h:24,
from /usr/include/sys/socket.h:28,
from server.c:4:
/usr/include/sys/types.h:235: error: conflicting types for ‘blkcnt_t’
/usr/include/linux/types.h:124: error: previous declaration of ‘blkcnt_t’ was here
server.c: In function ‘main’:
server.c:45: warning: implicit declaration of function ‘htons’
server.c: In function ‘sigint’:
server.c:144: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’
server.c:145: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’发布于 2010-01-18 01:02:59
您不应该包含来自linux/的内容,这是用户空间程序不支持的。
看起来您还缺少一些include,因为您收到了htons()的警告。
此外,您应该在格式字符串中使用%ld,而不仅仅是%d来打印long int变量。
发布于 2010-01-18 01:09:03
假设您的编译环境是正确的,我怀疑C宏的定义是不应该的,或者是一个不应该定义的宏,这导致了不兼容的类型定义。查看有问题的头文件,以确定该宏可能是什么。
https://stackoverflow.com/questions/2081763
复制相似问题