Error #include nested too deeply
转载:http://blog.csdn.net/ysdaniel/article/details/7043395
出现 Error #include nested too deeply 原因是:
头文件相互包含。
例如,一个工程中bsp.h 包含 LocDongle.h, LocDongle.h又包含bsp.h,
编译时就会报Error #include nested too deeply 。
解决办法:
1、将两个头文件共用的那一部分抽出来单独建一个头文件。
2、加预处理#ifndef.. #define...#endif
- //bsp.h
- #ifndef _BSP_H_
- #define _BSP_H_
- #include "LocDongle.h"
- #endif
- //LocDongle.h
- #ifndef _LOCDONGLE_H_
- #define _LOCDONGLE_H_
- #include "bsp.h"
- #endif
- <span style="font-family: simsun; line-height: 23px; "></span><pre><div><span style="line-height: 18px; color: rgb(0, 128, 0); ">//</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">bsp.h</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">
- </span><span style="line-height: 18px; color: rgb(0, 0, 0); ">#ifndef _BSP_H_</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">//</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">文件开始、第一行</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">
- </span><span style="line-height: 18px; color: rgb(0, 0, 255); ">#define</span><span style="line-height: 18px; color: rgb(0, 0, 0); "> _BSP_H_</span><span style="line-height: 18px; color: rgb(0, 0, 0); ">
- #include </span><span style="line-height: 18px; color: rgb(128, 0, 0); ">"</span><span style="line-height: 18px; color: rgb(128, 0, 0); ">LocDongle.h</span><span style="line-height: 18px; color: rgb(128, 0, 0); ">"</span><span style="line-height: 18px; color: rgb(0, 0, 0); ">
- ...</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">//</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">内容,所有的函数声明等等放这里</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">
- </span><span style="line-height: 18px; color: rgb(0, 0, 255); ">#endif</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">//</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">文件末尾</span><span style="line-height: 18px; color: rgb(0, 0, 0); ">
- </span><span style="line-height: 18px; color: rgb(0, 128, 0); ">//</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">LocDongle.h</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">
- </span><span style="line-height: 18px; color: rgb(0, 0, 0); ">#ifndef _LOCDONGLE_H_</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">//</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">文件开始、第一行</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">
- </span><span style="line-height: 18px; color: rgb(0, 0, 255); ">#define</span><span style="line-height: 18px; color: rgb(0, 0, 0); "> _LOCDONGLE_H_</span><span style="line-height: 18px; color: rgb(0, 0, 0); ">
- #include </span><span style="line-height: 18px; color: rgb(128, 0, 0); ">"</span><span style="line-height: 18px; color: rgb(128, 0, 0); ">bsp.h</span><span style="line-height: 18px; color: rgb(128, 0, 0); ">"</span><span style="line-height: 18px; color: rgb(0, 0, 0); ">
- ...</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">//</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">内容,所有的函数声明等等放这里</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">
- </span><span style="line-height: 18px; color: rgb(0, 0, 255); ">#endif</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">//</span><span style="line-height: 18px; color: rgb(0, 128, 0); ">文件末尾</span></div><div><span style="line-height: 18px; color: rgb(0, 128, 0); ">
- </span></div></pre><br>
- <p></p>
- <pre></pre>
- <br>
- <span style="font-family:simsun; font-size:14px; line-height:23px">头文件保护有用, 可以这样重复包含<br>
- 头文件包含其实就是在包含的位置展开它而已,<br>
- 你如果a.h包含了b.h<br>
- b.h又包含了a.h<br>
- 如果你使用了#ifndef.. #define...#endif的话<br>
- 你在一个.c文件中包含a.h那么它里面包含的b.h中包含的a.h将不会重复包含。</span><br>
- <p></p>
- <p><span style="font-family:simsun; font-size:14px; line-height:23px"><span style="font-family:simsun; font-size:14px; line-height:23px"><span style="font-family:simsun; font-size:14px; line-height:23px"><span style="font-family:simsun; font-size:14px; line-height:23px">头文件的嵌套一定要防止不断的包含,处于一个无限的循环!</span><br>
- </span></span></span></p>
Error #include nested too deeply的更多相关文章
- mac 安装 报错 "/usr/local/include/stdint.h:2:10: error: #include nested too deeply"
报错详细信息 构建错误 - “#include嵌套太深” /usr/local/include/stdint.h:2:10: error: #include nested too deeply #in ...
- Error getting nested result map values for 'company'. Cause: java.sql.SQLException: Invalid value for getInt() - 'NFHK188'
我今天遇到一个我不解的问题,是mybatis多对一关系查询出问题了,但是我自己还是解决了,在网上也查过那个错误,可是找不到我想要的.不知道你们遇到过没有,我接下来分享给大家.希望我这个第一篇博客能帮助 ...
- pip install py-stringsimjoin error: INCLUDE environment variable is empty
在用pip install py-stringsimjoin的时候报错error: INCLUDE environment variable is empty,后来在网上搜索下了说是需要下载安装VCF ...
- C语言中#ifdef,#ifndef和#endif的作用
现在规定一下头文件书写规范, 根据陈皓编写的跟我一起些makefile,一定要记住:头文件中应该只是声明,而定义应该放在C/C++文件中.否则如果出现有定义,比如头文件中有int a =2;如果有多个 ...
- gcc编译错误表
conversion from %s to %s not supported by iconv”iconv 不支持从 %s 到 %s 的转换” iconv_open”iconv_open” no ic ...
- 【翻译】R 中的设计模式
目录 R 中的设计模式 不动点算法 包装器模式 接口模式 柯里化(Currying) 闭包(Closures) 缓存模式 计数器模式 R 中的设计模式 本文翻译自 Design Patterns in ...
- System Error Codes
很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...
- winerror.h中的内容(可以查看last error对应)
/************************************************************************* ** winerror.h -- error co ...
- pod出现include of non-modular header inside framework module 错误
今天打包pod 的时候 出现的错误 -> AFNetworking+RX (3.1.0.18) - ERROR | [iOS] xcodebuild: Returned an unsuccess ...
随机推荐
- HTML5头部标签备忘
DOCTYPE DOCTYPE(Document Type),该声明位于文档中最前面的位置,处于html 标签之前,此标签告知浏览器文档使用哪种HTML 或者XHTML 规范. 推荐使用HTML5 推 ...
- MongoDB学习(2)—Node.js与MongoDB的基本连接示例
前提 已经安装了node.js和MongoDB,本文使用的node.js是v0.12.0,MongoDB是3.0.0. 初始化数据 启动MongoDB服务,在test数据库中插入一条实例数据: db. ...
- HDU 5918 Sequence I KMP
Sequence I Problem Description Mr. Frog has two sequences a1,a2,⋯,an and b1,b2,⋯,bm and a number p ...
- 仿IOS圆形下载进度条
/** * Created by C058 on 2016/5/25. */ public class MyHoriztalProgressBar extends ProgressBar { priv ...
- Loadrunner中参数化实战(8)-Unique+Each occurrence
参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Unique+Each occurrence 设置迭代4次Action 结果如下:
- 深入理解java中的synchronized关键字
synchronized 关键字,代表这个方法加锁,相当于不管哪一个线程A每次运行到这个方法时,都要检查有没有其它正在用这个方法的线程B(或者C D等),有的话要等正在使用这个方法的线程B(或者C D ...
- 《锋利的jQruery》读书笔记
由于是一边看书一边练习,所以干把笔记写在html文档中.想看的同学可以复制到一个html文档中,结合浏览器查看.不得不说<锋利的jQuery>是本好书,建议好好看看.尊重知识产权,请购买正 ...
- 2016.8.21 JavaScript 入门
1.JavaScript的数据类型: ①undefined ②null ③boolean ④string ⑤symbol ⑥number, object 2.在JavaScript中所有的变量和 ...
- redis 的安装
1: redis 是什么 Redis is an open source (BSD licensed), in-memory data structure store, used as databas ...
- .NET开源项目常用记录
综合类 微软企业库 微软官方出品,是为了协助开发商解决企业级应用开发过程中所面临的一系列共性的问题, 如安全(Security).日志(Logging).数据访问(Data Access).配置管理( ...