关于编译报错“dereferencing pointer to incomplete type...
今天同事问了我一个问题,他make的时候报错,“第201行:dereferencing pointer to incomplete type”,我随即查阅了很多资料,也没看出个所以然。最后问题得到了解决,也懂得了原理,遂记录一下。
他的问题具体是这样。
|
1
2
3
4
5
6
|
#include <netinet/ip_icmp.h>...struct icmp* aaa; aaa = (struct icmp*)malloc(sizeof(struct icmp)); //假设是第200行; aaa->icmp_type=1; //假设是201行;... |
make的时候第201行报错:dereferencing pointer to incomplete type。
首先说一下这个报错的意思,通俗的说就是,试图访问该pointer指向的变量,却发现该变量是一个不完整的类型,多出错于访问结构体联合体的成员。从代码中可看出来,是从201行开始才真正的访问icmp_type指向的变量,200行还没访问。
于是我就猜想,是不是struct icmp没有定义呢?遂粗略的查看了/usr/include/netinet/ip_icmp.h文件,发现有struct icmp的定义。很奇怪,不是吗?经过写了一些demo测试,最终的结论是,确实没有struct icmp的定义!
看到这里,更奇怪了。为什么是这样的结论呢?细看/usr/include/netinet/ip_icmp.h文件,会发现struct icmp的定义被包含在一个宏里面j,如下面所示:
|
1
2
3
4
5
6
7
8
9
|
...#ifdef __USE_BSD...struct icmp {...}...#endif /*END OF ifdef __USE_BSD*/... |
看到这里应该就明白了,编译的时候,如果编译命令 gcc ...里面没有加入 -D__USE_BSD的话,那么struct icmp的定义是不会被include进来的,所以就导致了前面的第201行报错:dereferencing pointer to incomplete type,也就是这样导致我开始一直想不明白,明明有定义,为何却说是不完整的类型。于是为了验证这个结论,我写了一个小demo来测试,发现加 -D__USE_BSD就编译通过,否则就编译不通过。
在解决这个问题的过程中,我写了不少demo,,下面总结一下。
1.如果报错“dereferencing pointer to incomplete type”, 先试图找一下该行的那个结构体变量的定义是否能找到,可使用grep "struct xxx" /usr/include -R命令递归搜索/usr/include目录,如找到,可在.c文件中#include,如果是非标准头文件就要在编译命令中加入-I头文件目录,例如 (-I/usr/local/xxx/include)。
2.如果#include之后仍然报错“dereferencing pointer to incomplete type”,试图仔细查看该文件,查看该结构体的定义是否被某个编译宏给包裹了,如果确实处于某个编译宏的包裹内,在编译命令里面增加 -D编译宏(如-D__USE_BSD)
经过上面两个步骤以后,基本上能解决“dereferencing pointer to incomplete type”报错了
转自:http://my.oschina.net/michaelyuanyuan/blog/68203?fromerr=quiozj2B
关于编译报错“dereferencing pointer to incomplete type...的更多相关文章
- 编译报错dereferencing pointer to incomplete type
关于编译报错“dereferencing pointer to incomplete type... 多是没找到结构体的定义,可以在本地复制其定义试试. 参考: http://my.oschina.n ...
- error: dereferencing pointer to incomplete type
/******************************************************************************* * error: dereferenc ...
- 使用C#模拟Outlook发送邮件,代码编译报错
添加OutLook API using OutLook = Microsoft.Office.Interop.Outlook; 发送邮件方法 public void SendEmail() { Out ...
- cordova编译报错:Execution failed for task ':processDebugResources'
cordova编译报错:Execution failed for task ':processDebugResources' 引发这个错误的最扩祸首就是一个中文命名的文件,不知道什么时候加入的,我写了 ...
- Maven-010-maven 编译报错:Failure to ... in ... was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced.
今晚在编译 maven 项目的时候,命令行报错,出现 Failure to ... in ... 类似错误,详细的错误信息如下所示: [INFO] -------------------------- ...
- [Intellij] 编译报错 javacTask
报错信息: Idea 编译报错 javacTask: 源发行版 1.6 需要目标发行版 1.6 解决方案:
- jenkis编译报错:需要class,interface或enum
现象: 1.jenkis编译报错:需要class,interface或enum 2.使用ant进行编译ok. 解决方法: 1. Jenkis重新编译一个以前成功的svn版本,直至编译成功. 2.Jen ...
- 对arm指令集的疑惑,静态库运行,编译报错等问题
转载自http://www.jianshu.com/p/4a70aa03a4ea?utm_campaign=hugo&utm_medium=reader_share&utm_conte ...
- xocde7下导入libsqlite3.tbd编译报错的解决办法
在xocde7下没有libsqlite3.dylib,只有libsqlite3.tbd,然后我导入了tbd.编译报错error: /Applications/Xcode.app/Contents/De ...
随机推荐
- File API 读取上传的文件
1, 在html 文档中,<input type="file"> 我们可以选择文件进行上传,但这时只能上传一个文件.如果加上multiple 属性,可以上传多个文件,上 ...
- VMware Ubuntu Kaldi
1.VMware10.0 秘钥网上搜就好了 2.ubuntu12.04 (1)安了几次14.04,16.04,12.04,最后窗口和分辨率的bug 还是没有解决 (2)终端显示菱形乱码的解决:直接用英 ...
- mysql 命令(二)
1.创建数据库,并制定默认的字符集是utf8. CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_g ...
- 【OS】分页和分段
在网上找到了一个比较形象的比喻 打个比方,比如说你去听课,带了一个纸质笔记本做笔记.笔记本有100张纸,课程有语文.数学.英语三门,对于这个笔记本的使用,为了便于以后复习方便,你可以有两种选择. ...
- python3 生成器&迭代器
#Author by Andy#_*_ coding:utf-8 _*_import timefrom collections import Iterable#列表生成式def func(): lis ...
- 严重:Error listenerStart
转自: http://1985wanggang.blog.163.com/blog/static/7763833200942611050436/ 近日浏览论坛,发现好多人提问,都说在运行web程序时, ...
- 在myeclipse2014使用git上传github
简介 首先在myeclipse中安装github客户端插件,这里就不说了,跟安装svn客户端插件一样的步骤 1.选中要push到github的工程右键team->share project-&g ...
- C/C++面试题总结
腾讯阿里面试题总结:1. 多态机制2. 排序算法(快排.堆排)3. 程序内存分配4. unix多线程5. 哈希查找6. oop特点7. 素数(优化)8. 字符串掩膜操作(内存紧凑)9. 多边形相交10 ...
- 268. Missing Number -- 找出0-n中缺失的一个数
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- JQmeter显示进度条
<script type="text/javascript"> $(function(){ var percent = "${evICVDBean.resul ...