一个项目中,多个.h和多个.cpp文件之间相互引用

天狗ncfxy 2014-10-16 11:24:18
我的是这样的a.h对应a.cpp;b.h对应b.cpp,b.cpp里面有有main函数,要调用a里的,在头文件中加入#include "a.h",这样报错,
请大神解答。
...全文
588 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
女神打Boss 2014-10-16
  • 打赏
  • 举报
回复
没有这.h文件啊
赵4老师 2014-10-16
  • 打赏
  • 举报
回复
The #include Directive The #include directive tells the preprocessor to treat the contents of a specified file as if those contents had appeared in the source program at the point where the directive appears. You can organize constant and macro definitions into include files and then use #include directives to add these definitions to any source file. Include files are also useful for incorporating declarations of external variables and complex data types. You only need to define and name the types once in an include file created for that purpose. Syntax #include "path-spec" #include <path-spec> The path-spec is a filename optionally preceded by a directory specification. The filename must name an existing file. The syntax of the path-spec depends on the operating system on which the program is compiled. Both syntax forms cause replacement of that directive by the entire contents of the specified include file. The difference between the two forms is the order in which the preprocessor searches for header files when the path is incompletely specified. Syntax Form Action Quoted form This form instructs the preprocessor to look for include files in the same directory of the file that contains the #include statement, and then in the directories of whatever files that include (#include) that file. The preprocessor then searches along the path specified by the /I compiler option, then along paths specified by the INCLUDE environment variable. Angle-bracket form This form instructs the preprocessor to search for include files first along the path specified by the /I compiler option, then along the path specified by the INCLUDE environment variable. The preprocessor stops searching as soon as it finds a file with the given name. If you specify a complete, unambiguous path specification for the include file between two sets of double quotation marks (" "), the preprocessor searches only that path specification and ignores the standard directories. If the filename enclosed in double quotation marks is an incomplete path specification, the preprocessor first searches the “parent” file’s directory. A parent file is the file containing the #include directive. For example, if you include a file named file2 within a file named file1, file1 is the parent file. Include files can be “nested”; that is, an #include directive can appear in a file named by another #include directive. For example, file2, above, could include file3. In this case, file1 would still be the parent of file2 but would be the “grandparent” of file3. When include files are nested, directory searching begins with the directories of the parent file and then proceeds through the directories of any grandparent files. Thus, searching begins relative to the directory containing the source currently being processed. If the file is not found, the search moves to directories specified by the /I compiler option. Finally, the directories specified by the INCLUDE environment variable are searched. The following example shows file inclusion using angle brackets: #include <stdio.h> This example adds the contents of the file named STDIO.H to the source program. The angle brackets cause the preprocessor to search the directories specified by the INCLUDE environment variable for STDIO.H, after searching directories specified by the /I compiler option. The following example shows file inclusion using the quoted form: #include "defs.h" This example adds the contents of the file specified by DEFS.H to the source program. The double quotation marks mean that the preprocessor searches the directory containing the parent source file first. Nesting of include files can continue up to 10 levels. Once the nested #include is processed, the preprocessor continues to insert the enclosing include file into the original source file. Microsoft Specific To locate includable source files, the preprocessor first searches the directories specified by the /I compiler option. If the /I option is not present or fails, the preprocessor uses the INCLUDE environment variable to find any include files within angle brackets. The INCLUDE environment variable and /I compiler option can contain multiple paths separated by semicolons (;). If more than one directory appears as part of the /I option or within the INCLUDE environment variable, the preprocessor searches them in the order in which they appear. For example, the command CL /ID:\MSVC\INCLUDE MYPROG.C causes the preprocessor to search the directory D:\MSVC\INCLUDE for include files such as STDIO.H. The commands SET INCLUDE=D:\MSVC\INCLUDE CL MYPROG.C have the same effect. If both sets of searches fail, a fatal compiler error is generated. If the filename is fully specified for an include file with a path that includes a colon (for example, F:\MSVC\SPECIAL\INCL\TEST.H), the preprocessor follows the path. For include files specified as #include "path-spec", directory searching begins with the directory of the parent file and then proceeds through the directories of any grandparent files. Thus, searching begins relative to the directory containing the source file containing the #include directive being processed. If there is no grandparent file and the file has not been found, the search continues as if the filename were enclosed in angle brackets. END Microsoft Specific
铖邑 2014-10-16
  • 打赏
  • 举报
回复
可能跟a.h不是一个目录的,所以有问题 楼主哪个地方?就近找个朋友或公司学习
天狗ncfxy 2014-10-16
  • 打赏
  • 举报
回复
已经加添加到项目中了,face_detection.cpp里面可以识别。 其实我想有没有个好的项目的结构学习下,规范一下自己的代码。
铖邑 2014-10-16
  • 打赏
  • 举报
回复
找下face_detection.h文件
szl956739895 2014-10-16
  • 打赏
  • 举报
回复
没有放在同一路径下吧,默认是同一路径的
xian_wwq 2014-10-16
  • 打赏
  • 举报
回复
引用 楼主 ncfxy 的回复:
我的是这样的a.h对应a.cpp;b.h对应b.cpp,b.cpp里面有有main函数,要调用a里的,在头文件中加入#include "a.h",这样报错, 请大神解答。
查一下a.h的具体位置,如果不在同一目录下, 需要用相对路径
小菜寻路 2014-10-16
  • 打赏
  • 举报
回复
#include "a.h" 会优先在项目所在的当前目录中查找,比如你项目在D:\Projects\ 那么你的头文件就得放在D:\Projects\a.h。这样才能找到

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧