#include directive

VC编程-预编译头文件(precompiled header) <br /><br />预编译头文件(precompiled header)<br /> <br />今天在写程序的时候,突然发现要测试的代码是用c写的,还是用gcc编译的,可是我已经建立了测试的相关环境,没办法,只能一步步的改了,将相关的头文件、结构和变量移植以后,编译了一下(只编译了C文件),竟然出错,出错信息为:fatal error C1010: unexpected end of file while looking for precompiled header directive<br />然后 阅读详情

最近用google test/mock 框架写Unit Test的时候, 碰到的关于覆盖头文件的问题.

  1. include的搜索顺序, 包括编译器选项来强制指定
  2. include的写法包含了相对路径
  3. include当前路径查找如何覆盖

问题远不止者3项. 下面的文章可以解决这些问题, 需要稍微思考以下即可.

The #include Directive

The following coming from the gcc documenation:

Both user and system header files are included using the preprocessing directive #include. It has three variants:

#include <file>

This variant is used for system header files. It searches for a file named file in a list of directories specified by you, then in a standard list of system directories. You specify directories to search for header files with the command option -I (see section 1.9 Invoking the C Preprocessor). The option -nostdinc inhibits searching the standard system directories; in this case only the directories you specify are searched.

The parsing of this form of #include is slightly special because comments are not recognized within the <...>. Thus, in #include <x/*y> the /* does not start a comment and the directive specifies inclusion of a system header file named x/*y. Of course, a header file with such a name is unlikely to exist on Unix, where shell wildcard features would make it hard to manipulate.

The argument file may not contain a > character. It may, however, contain a < character.

#include “file”

This variant is used for header files of your own program. It searches for a file named file first in the current directory, then in the same directories used for system header files. The current directory is the directory of the current input file. It is tried first because it is presumed to be the location of the files that the current input file refers to. (If the -I- option is used, the special treatment of the current directory is inhibited.)

The argument file may not contain " characters. If backslashes occur within file, they are considered ordinary text characters, not escape characters. None of the character escape sequences appropriate to string constants in C are processed. Thus, #include "x\n\\y" specifies a filename containing three backslashes. It is not clear why this behavior is ever useful, but the ANSI standard specifies it.

#include anything else

This variant is called a computed #include. Any #include directive whose argument does not fit the above two forms is a computed include. The text anything else is checked for macro calls, which are expanded (see section 1.4 Macros). When this is done, the result must fit one of the above two variants–in particular, the expanded text must in the end be surrounded by either quotes or angle braces.

This feature allows you to define a macro which controls the file name to be used at a later point in the program. One application of this is to allow a site-specific configuration file for your program to specify the names of the system include files to be used. This can help in porting the program to various operating systems in which the necessary system header files are found in different places.

difference between #include <filename> and #include “filename”

In practice, the difference is in the location where the preprocessor searches for the included file.

#include <filename>

For #include <filename> the preprocessor searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE. This method is normally used to include standard library header files.

#include “filename”

For #include “filename” the preprocessor searches first in the same directory as the file containing the directive, and then follows the search path used for the #include <filename> form. This method is normally used to include programmer-defined header files.

A more complete description is available in the GCC documentation on search paths.

What if you want to reuse some files that you want to use different headers

For short and the following applys for gcc:

  1. use -I- option to inhibit the current directory treatment
  2. use -iquote dir option to force the cpp to search the dir you specified

Reference

what-is-the-difference-between-include-filename-and-include-filename
Where Does GCC Look to Find its Header Files?

#systemverilog# 关键字之 `include(1) 今天,我们学习一下 SystermVerilog_3.1a 语法参考书【25.3】章节。关于 `include 关键字的使用。 基本语法格式: include_compiler_directive ::= ‘include "filename" | ‘include <filename> When the filename is an absolute path, only that filename is included and only the double quote fo 阅读详情

相关推荐

Star CCM+中的物性参数(定值、多项式、查表)

仿真过程中我们一定会遇到设置物性参数的问题,对于固定的物性参数还好说,直接输入一个固定的值即可。但是对于冷却液、气体、两相流等,物性参数是随着温度或温度和压力变化的。此时就涉及到多项式和查表。首先创建物理连续体,选择计算模型。

2201_75375391的博客 2966

深入浅出 C++:#include Directive PART 1 - Include Guard

除了基本语法外,使用 C++ 提供的函数库、类型定义等,都需要使用 #include 引入 header file,写法如下: #include &amp;amp;amp;amp;amp;lt;iostream&amp;amp;amp;amp;amp;gt; #include &amp;amp;amp;amp;amp;lt;vector&amp;amp;amp;amp;amp;gt; #include &amp;amp;amp;amp;amp;lt;string&a

索拉的天空 2293

Cortex-M异常处理深度解析:从HardFault到调试实战

在嵌入式开发中,Cortex-M系列处理器的异常处理机制是保障系统可靠性的核心。然而,面对HardFault、MemManage、BusFault等异常时,开发者往往陷入迷茫。本文结合SEGGER AN00016和Keil AN209两篇权威文档,深入剖析异常根源、寄存器解析及调试技巧,并通过代码实例演示如何快速定位问题。

汽车电子软件领域知识分享 2537

解决“extra tokens at end of #include directive”警告

在引入一个源数据文件时产生的告警: 源代码是这样的 double A[5000*36] = { #include "input.dat"; } 应该修改成 double A[5000*36] = { #include "input.dat" }

weixin_44528747的博客 9405

UE4_SpeedTree Shader源码分析

目录 1.UMaterialExpressionSpeedTree::Compile 2.Compiler->SpeedTree 3.GetSpeedTreeVertexOffset 4.Scene中的SpeedTree应用 (Scene->UpdateSpeedTreeWind) 5.GetSpeedTreeVertexOffsetInner 由于之后做风场,也需要在S...

zzgyy123的专栏 2639

双轮差动机器人SLAM实战:轮速里程计从建模到精度验证(附Matlab代码)

本文详细介绍了双轮差动机器人SLAM系统中轮速里程计的实现全流程,包括核心原理、建模方法、Matlab代码实现及精度验证。通过轮速仪数据建模和连续积分算法,提升定位精度,并附有完整的误差分析和工程优化技巧,为开发者提供实用参考。

weixin_29050271的博客 225

QT出现“查找/添加槽错误”解决方法之一

出现 The class containing "Ui::MainWindow" could not be found in E:\QTproject\osgProjects\2020_810_DEMO\mainwindow.h E:\QTproject\osgProjects\2020_810_DEMO\Function.h. Please verify the #include-directives. 类似错误,重启qt Creator可解决。

qq_36881934的博客 3479

数学建模灵敏性分析(一阶、二阶灵敏度)python代码+懒人专用版

对于勉强看懂了灵敏度分析的同学来说,本文给出一个方便移植、修改的python程序,可以很方便地进行灵敏度分析。

春江花朝秋月夜 1万+

深入浅出 C++:#include Directive PART 2 - 使用上的各种注意事项、经验谈

标准 Header File C++ 并没有规定 header file 的后缀名为何。约定俗成的习惯,是将 .h 或 .hpp 当作 header file 的后缀名。而 C++ 标准库

索拉的天空 673

【vivado PG学习】1 PG168:7 Series FPGAs Transceivers官方配置方法学习笔记

介绍: The 7 series FPGAs Transceivers Wizard LogiCORE™ IP 自动创建配置7系列fpga 收发器的HDL封装。向导可以配置一个或多个支持行业主流标准的高速串行收发器。或者从零开始支持各种自定义协议。 功能: 创建配置7系列fpga 收发器的HDL封装。 自动对模拟设置进行配置。 预定义了提供Aurora 8B/10B, Aurora 64B/66B, CEI-6G,DisplayPort, Interlaken, Open Base StationAr..

w0shishabi的博客 5万+

易康eCognition9.0分类|规则集和机器学习的方法的面向对象的多尺度分割分类

基于易康eCognition9.0软件的规则集和机器学习的方法的面向对象的多尺度分割分类

weixin_46493028的博客 1万+

Error: invalid preprocessing directive #INCLUDE

2)问题分析,文件都有。

xxxx的博客 665

yanshee 机器人全流程指南

2.点击yanshee app右上角根据提示操作 3.当手机显示成功连接 ,按下机器人胸前按钮说出“ip地址”4.根据机器人播报的ip地址加上:8888使用浏览器访问,你就会看到 jupyterd的界面,里面可以新建文件也可以改他存在的文件。我们使了yanshee机器人,这个是面向K12、中高职、高校学生推出的开源人形机器人教育平台,应用于课程教学、竞赛、科研活动等场景。我们接下来可以根据这些apl做许多好玩的,比如控制他运动,跳舞唱歌,it`s easy。注意电脑,手机,机器人必须连同一个网。

qq_44827929的博客 7631

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

warning: extra tokens at end of #include directive

用gcc编译源文件时出现的. collect2: ld returned 1 exit status 这个错误究其原因应该是这个:某些自定义函数在头文件中声明了,在实现文件却没有用到。 下面是各种情况,自己查找错误原因时,碰到的。 Given a huge p

StoneCamel 1万+

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

error: invalid preprocessing directive 问题解决

在Ubuntu下使用CMakelist 编译,遇到了这个问题。问题提示的很明显,要仔细看错误说明,不要着急。 error: invalid preprocessing directive 无效的预处理指令 解释:#include 是预编译的指令,告诉编译器该去什么路径下找文头件,并且展开。这里的include写成inclde。所以编译器无法识别这个指令。导致头文件包含失败。随即导致后面的错误。 ...

3万+

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

VC++6.0中常出现的"unexpected end of file while looking for precompiled header directive"的问题解决方法

<br />如何解决:"fatal error C1010:VC++6.0中常出现的"unexpected end of file while looking for precompiled header directive"的问题? <br />我想大家在VC6.0中经常回遇到这样的问题,如何解决呢?<br />1、看看是否缺少“;”,“}”   <br />  隐藏得深的是宏、.h文件的问题就要费点心思了<br />2、一定是你在类的部分定义被删除了,M$在每个类中定义一些特殊的常量,是成对的,如下:

NightAngle的专栏 1020

关于VC的一些编译错误

1、fatal error C1010: unexpected end of file while looking for precompiled header directive 解决:在cpp文件中加入#include "StdAfx.h"

吖吖狼 的专栏 808

c语言adds什么用法,C语言中,#include的用法:#include "" 和 #include<>区别

采用 "":依次搜索当前目录、包括/I编译开关的路径、包括INCLUDE环境变量的路径 采用<>:依次搜索包括/I编译开关的路径、包括INCLUDE环境变量的路径The #include DirectiveThe #include directive tells the preprocessor to treat the contentsof a specified file as ...

weixin_39600319的博客 562

[Error] invalid preprocessing directive #inclued问题解决

[Error] invalid preprocessing directive #inclued问题解决

VLOKL的博客 7972

linux的as编译文件,Fedora编译vivi的**-linux-as: unrecognized option '-__ASSEMBLY__'解决

一,编译环境:gcc-2.95.3 ; Fedora Core 9 ; vivi-0.1.4(带网络版)二,错误描述:编译VIVI时,出现错误提示:“/opt/host/armv4l/bin/armv4l-unknown-linux-as -D__ASSEMBLY__ -I/home/echokuki/s3c2410/Experimentbck/Bootloaderv1/Bootloader/in...

weixin_42520580的博客 434

Velocity(8)——引入指令和#Parse 指令

#Include和#Parse都是用于将本地文件引入当前文件的指令,而且被引入的文件必须位于TEMPLATE_ROOT。这两者之间有一些区别。 #Include 被#Include引入的文件,其内容不会被Velocity引擎解析,所以这些文件应该是静态模板,即不含有VTL的模板。使用#Include()指令时,参数是被双引号括起来的文件名或者是表示文件名的变量。如果有多个文件,以逗号隔

u014704496的专栏 7712

Error[Pe011]: unrecognized preprocessing directive

最近编程出现了一个这样的报错,unrecognized preprocessing directive (无法识别的预处理指令) 预处理功能常用的主要以下3种: 1.宏定义 2.文件包含 3.条件编译 如果出现这样的报错,查看预编译指令是否发生错误,例如关键词有没有写错(include,define ifndef endif等),是不是加了不该加的符号(如: ;)...

AAlonso的博客 1万+

关于include <iostream> using namespace std; 的新发现

#关于include using namespace std; 的新发现 在代码 #include <stdlib.h> #include<stdio.h> #define MaxSize 40 int next[MaxSize]; void GetNext(SqString t) { int j, k; j = 0; k = -1; next[0] = -1; w...

weixin_44333471的博客 3001

Velocity(7)——引入指令和#Stop指令

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34247032的博客 173
上一篇: 友元类和友元函数
下一篇: Multiple and Virtual Inheritance
cuiyong_cn
博客等级 码龄16年 9粉丝 66原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值