gcc编译出现:error: dereferencing pointer to incomplete type
使用gcc编译c文件出现如下错误:
getIP.c:14: warning: implicit declaration of function ‘gethostname’
getIP.c:20: warning: implicit declaration of function ‘getaddrinfo’
getIP.c:21: error: dereferencing pointer to incomplete type
getIP.c:23: error: dereferencing pointer to incomplete type
getIP.c:25: error: dereferencing pointer to incomplete type
编译方式:
gcc -std=c99 getIP.c
编译环境:
Red Hat Enterprise Linux Server release 6.4
源文件getIP.c:
#include <sys/socket.h>
#include <netdb.h>
#include <sys/types.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h> #include <stdio.h>
#include <stdlib.h>int main(int argc,char* argv[])
{
char host_name[128]={0};
gethostname(host_name, sizeof(host_name));
printf("host_name:%s\n",host_name);struct addrinfo *ailist=NULL,*aip=NULL;
struct sockaddr_in *saddr;
char *addr;
int ret=getaddrinfo(host_name,"ftp",NULL,&ailist);
for(aip=ailist; aip!=NULL; aip=aip->ai_next)
{if(aip->ai_family==AF_INET){saddr=(struct sockaddr_in*)aip->ai_addr;addr=inet_ntoa(saddr->sin_addr);}printf("addr:%s\n",addr);
}
getchar();
return 0;
}
以上是问题的主要描述,很奇怪的是换成g++编译没有任何问题:
g++ -std=c++0x getIP.c
在CSDN论坛中发帖寻求帮助,几度困惑和无助,但皇天不负有心人,此问题的出现是因为gcc使用了编译选项-std=c99,去掉该编译选项,顺利通过编译。 原因可能是struct addrinfo 的定义并不在c99标准中。
我们可以使用最新的c11标准,但是前提是gcc需要4.7版本之后,才真正支持c11的。
gcc编译出现:error: dereferencing pointer to incomplete type相关推荐
- 解决编译错误:dereferencing pointer to incomplete type 的办法
在使用c语言写程序时,可能遇到错误:error :dereferencing pointer to incomplete type.其实,这个错误是指针指向的结构体类型没有定义. 原因可能有很多,但最 ...
- error: dereferencing pointer to incomplete type
/******************************************************************************** error: dereferenci ...
- 关于编译报错“dereferencing pointer to incomplete type...
FORM:https://my.oschina.net/michaelyuanyuan/blog/68203 今天同事问了我一个问题,他make的时候报错,"第201行:dereferenc ...
- 在linux 下编译c程序时“ error:dereferencing pointer to incomplete type”的问题
在linux 下编译c程序时经常会遇到" error:dereferencing pointer to incomplete type"的问题,该问题的原因是:结构体定义不规范造成 ...
- error :dereferencing pointer to incomplete type解决办法
C代码编译时出现如下错误: error :dereferencing pointer to incomplete type 即引用指针到不完全的类型 引起该错误的原因是指针指向的结构体类型没有定义. ...
- error:dereferencing pointer to incomplete type
字面意义是不完整的类型,一般出现在定义结构体指针类型声明的时候.真正出现的问题原因是这个结构体根本就没有定义,或者是定义的头文件并没有被正确引用进来.尤其高版本的kernel 向低版本进行移植中经常出 ...
- error: invalid use of incomplete type 'XXXX' ;error: forward declaration of 'XXXX' 声明改为包含头文件
error: invalid use of incomplete type 'XXXX' error: forward declaration of XXXX 声明改为包含头文件 class XXXX ...
- linux c之gcc编译出现error:lvalue required as unary ‘‘ operand解决办法
1.问题 今天搞epoll实现io复用的时候gcc编译出现这个错误lvalue required as unary '&' operand,如下图 2.解决办法 accept函数参数如下 in ...
- cygwin下编译报错 `addrinfo hints‘ has incomplete type and cannot be defined
今天在cygwin下编译一个linux项目时报了类似下面的错误: server.cpp:20: error: aggregate `addrinfo hints' has incomplete typ ...
最新文章
- 终于有人把JAVA虚拟机讲清楚了!
- excel一些操作技巧
- 总结2010展望2011
- Spark的Transformations算子(理解+实例)
- java jsp if else if_jsp页面使用if else语句 | 学步园
- 一文搞清楚 Spark 数据本地化级别
- redis配置文件的介绍
- Java基本数据类型的转换
- 普通人如何快速翻身?
- 【回文串5 重点+动态规划】LeetCode 132. Palindrome Partitioning II
- java开发和android开发_浅谈Java开发和Android开发的不同
- 2021华为软件精英挑战赛(粤港澳赛区复赛第八)
- python之pygame,详解坦克大战
- 〖Python零基础入门篇(62)〗- Python 中的魔法函数
- AI英雄 | 论人工智能与自由意志,请看尤瓦尔与李飞飞的这场“激辩”
- 当前有哪些流行的前端开发框架?
- centos 6.9部署svn服务器和客户端(客户端含windows、linux版本)
- 简单 Python 快乐之旅之:Python 基础语法之 JSON 专题
- H5、React Native、Native应用对比分析
- android 文字转化为图片格式,Android 文字生成图片