作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 mingw 上收到此错误:pr1.c 是文件名
我遇到了一些问题,然后添加了这样的库,但现在出现了这些错误:
$ gcc pr1.c -o pr1.exe -lwsock32 -lws2_32
pr1.c: In function 'main':
pr1.c:54:2: warning: incompatible implicit declaration of built-in function 'b
zero' [enabled by default]
C:\Users\rak\AppData\Local\Temp\ccMtb7Wt.o:pr1.c:(.text+0xc9): undefined refe
rence to `inet_pton'
C:\Users\rak\AppData\Local\Temp\ccMtb7Wt.o:pr1.c:(.text+0xe2): undefined refe
rence to `bzero'
C:\Users\rak\AppData\Local\Temp\ccMtb7Wt.o:pr1.c:(.text+0x1b5): undefined ref
erence to `bzero'
C:\Users\rak\AppData\Local\Temp\ccMtb7Wt.o:pr1.c:(.text+0x224): undefined ref
erence to `bzero'
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: C:\Users\rak\AppData\Local\Temp\ccMtb7Wt.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link
failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
最佳答案
#include <string.h>
错误消息告诉您 gcc 有 bzero
作为内置函数。但是如果范围内没有原型(prototype),您的用法将被视为引用返回 int
(默认返回类型)的函数。所以它与内置函数不匹配,gcc 只是将责任传递给链接器,而链接器同样找不到这样的函数。添加头文件,以便编译器找到正确的原型(prototype)。
您可能需要启用 bzero
,例如:
#define _BSD_SOURCE
如果这不能消除 bzero
错误,那么您确实应该放弃它并使用 memset
。
对于 inet_pton
,您还需要:
#include <arpa/inet.h>
这篇关于 Windows 上套接字编程的说明也可能有用:from Beej's Guide .
关于c - 在windows上编译socket proram时mingw出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15966357/
我是一名优秀的程序员,十分优秀!