转载: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

  1. //bsp.h
  2. #ifndef _BSP_H_
  3. #define _BSP_H_
  4. #include "LocDongle.h"
  5. #endif
  6. //LocDongle.h
  7. #ifndef _LOCDONGLE_H_
  8. #define _LOCDONGLE_H_
  9. #include "bsp.h"
  10. #endif
  1. <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); ">
  2. </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); ">
  3. </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); ">
  4. #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); ">
  5. ...</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); ">
  6. </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); ">
  7. </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); ">
  8. </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); ">
  9. </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); ">
  10. #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); ">
  11. ...</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); ">
  12. </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); ">
  13. </span></div></pre><br>
  14. <p></p>
  15. <pre></pre>
  16. <br>
  17. <span style="font-family:simsun; font-size:14px; line-height:23px">头文件保护有用, 可以这样重复包含<br>
  18. 头文件包含其实就是在包含的位置展开它而已,<br>
  19. 你如果a.h包含了b.h<br>
  20. b.h又包含了a.h<br>
  21. 如果你使用了#ifndef.. #define...#endif的话<br>
  22. 你在一个.c文件中包含a.h那么它里面包含的b.h中包含的a.h将不会重复包含。</span><br>
  23. <p></p>
  24. <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>
  25. </span></span></span></p>

Error #include nested too deeply的更多相关文章

  1. 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 ...

  2. Error getting nested result map values for 'company'. Cause: java.sql.SQLException: Invalid value for getInt() - 'NFHK188'

    我今天遇到一个我不解的问题,是mybatis多对一关系查询出问题了,但是我自己还是解决了,在网上也查过那个错误,可是找不到我想要的.不知道你们遇到过没有,我接下来分享给大家.希望我这个第一篇博客能帮助 ...

  3. pip install py-stringsimjoin error: INCLUDE environment variable is empty

    在用pip install py-stringsimjoin的时候报错error: INCLUDE environment variable is empty,后来在网上搜索下了说是需要下载安装VCF ...

  4. C语言中#ifdef,#ifndef和#endif的作用

    现在规定一下头文件书写规范, 根据陈皓编写的跟我一起些makefile,一定要记住:头文件中应该只是声明,而定义应该放在C/C++文件中.否则如果出现有定义,比如头文件中有int a =2;如果有多个 ...

  5. gcc编译错误表

    conversion from %s to %s not supported by iconv”iconv 不支持从 %s 到 %s 的转换” iconv_open”iconv_open” no ic ...

  6. 【翻译】R 中的设计模式

    目录 R 中的设计模式 不动点算法 包装器模式 接口模式 柯里化(Currying) 闭包(Closures) 缓存模式 计数器模式 R 中的设计模式 本文翻译自 Design Patterns in ...

  7. System Error Codes

    很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...

  8. winerror.h中的内容(可以查看last error对应)

    /************************************************************************* ** winerror.h -- error co ...

  9. pod出现include of non-modular header inside framework module 错误

    今天打包pod 的时候 出现的错误 -> AFNetworking+RX (3.1.0.18) - ERROR | [iOS] xcodebuild: Returned an unsuccess ...

随机推荐

  1. 跟着鸟哥学Linux系列笔记2-第10章VIM学习

    跟着鸟哥学Linux系列笔记0-扫盲之概念 跟着鸟哥学Linux系列笔记0-如何解决问题 跟着鸟哥学Linux系列笔记1 常用的文本编辑器:Emacs, pico, nano, joe, vim VI ...

  2. Node.js 究竟是什么?

    Node.js 究竟是什么? 一个 "编码就绪" 服务器 Node 是一个服务器端 JavaScript 解释器,它将改变服务器应该如何工作的概念.它的目标是帮助程序员构建高度可伸 ...

  3. APUE包含头文件"apue.h"问题

    下载源码 从unix高级编程书籍官网下载书籍的上的所有源码. wget http://www.apuebook.com/src.tar.gz 解压这个文件 tar -zxvf src.tar.gz 解 ...

  4. objective-c常用方法列表(总结)

    第1章 Objective-C学习环境准备 1.1 Objective-C基础 1.1.1 Objective-C的发展历程 1.1.2 Objective-C语言的特点 1.1.3 技术架构 1.2 ...

  5. apache服务器安装

    下载地址:http://www.apachehaus.com/cgi-bin/download.plx 全程按这篇来的,很顺利 http://www.cnblogs.com/yerenyuan/p/5 ...

  6. 智能车学习(八)——菜单的实现

    一.代码分享 1.头文件 #ifndef __MENU_H #define __MENU_H /***********宏定义************/ //页面声明 typedef enum Menu ...

  7. Linux学习笔记(1)Linux虚拟机安装过程中的知识点及常用管理工具

    1. VMware的相关知识 (1)建议的VMware的配置: CPU 主频1GHz以上 内存 1GB以上 硬盘 分区空闲空间8GB以上 (2)VMware创建快照 快照的作用是保存虚拟机的现有状态, ...

  8. WPD:Page Download Time Breakdown选项详解

    WPD:Page Download Time Breakdown选项详解 “页面下载时间细分”图显示每个页面组件下载时间的细分,可以根据它确定在网页下载期间事务响应时间缓慢是由网络错误引起还是由服务器 ...

  9. Java和数据库时间格式化格式

    JAVA: yyyy-MM-dd HH-mm-ss(大小HH表示24小时制); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd&q ...

  10. HTML5 重要标签及其属性学习

    1.google字体:<link href="https://fonts.googleapis.com/css?family=Lobster" rel="style ...