简体   繁体   English

在Xcode c ++项目中包含头文件

[英]Include header file in Xcode c++ project

I have a header file named Ah, another header file named Bh 我有一个名为Ah的头文件,另一个名为Bh的头文件

In Bh, 在Bh,

#include "XYZ/Ah"

but Xcode complains "XYZ/Ah" file not found. 但Xcode抱怨找不到“XYZ / Ah”文件。

I tried to make a subfolder XYZ in the folder where Bh is, and put Ah into XYZ, but the same error. 我试图在Bh所在的文件夹中创建一个子文件夹XYZ,并将Ah放入XYZ,但同样的错误。

How to solve this? 怎么解决这个? ===> Set parent folder of XYZ folder in project build setting "header search path". ===>在项目构建设置“标题搜索路径”中设置XYZ文件夹的父文件夹。 Problem resolved! 问题解决了!

I don't want to change the header file Bh - I want to keep the relative path "XYZ/Ah". 我不想改变头文件Bh - 我想保持相对路径“XYZ / Ah”。

PLEASE NOTE: Both Ah and Bh are added into project (dragging...), and their physical location is not same with group folder in Xcode project. 请注意:Ah和Bh都被添加到项目中(拖动...),它们的物理位置与Xcode项目中的组文件夹不同。 They may be in different folders in disk. 它们可能位于磁盘的不同文件夹中。

I am not particularly familiar with XCode but generally the compiler needs to know where to start looking when using relative include paths. 我对XCode并不是特别熟悉,但通常编译器需要知道在使用相对包含路径时从哪里开始查找。 For this reason, through compiler options or project options (since you are using an IDE), you must set the path to the directory that contains the directory XYZ. 因此,通过编译器选项或项目选项(因为您使用的是IDE),必须设置包含目录XYZ的目录的路径。 So if the path to XYZ is '/home/user/XYZ', then you need to add '/home/user/' to the search paths. 因此,如果XYZ的路径是'/ home / user / XYZ',那么您需要在搜索路径中添加'/ home / user /'。

Now this is generally speaking. 现在这是一般性的说法。 XCode may do it in a slightly other way but the point should be the same. XCode可以稍微以其他方式进行,但该点应该相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM