Include header file in Xcode c++ project

点点圈 提交于 2021-02-07 10:20:08

问题


I have a header file named A.h, another header file named B.h.

In B.h,

#include "XYZ/A.h"

but Xcode complains "XYZ/A.h" file not found.

I tried to make a subfolder XYZ in the folder where B.h is, and put A.h into XYZ, but the same error.

How to solve this? ===> Set parent folder of XYZ folder in project build setting "header search path". Problem resolved!

I don't want to change the header file B.h - I want to keep the relative path "XYZ/A.h".

PLEASE NOTE: Both A.h and B.h are added into project (dragging...), and their physical location is not same with group folder in Xcode project. They may be in different folders in disk.


回答1:


I am not particularly familiar with XCode but generally the compiler needs to know where to start looking when using relative include paths. 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. So if the path to XYZ is '/home/user/XYZ', then you need to add '/home/user/' to the search paths.

Now this is generally speaking. XCode may do it in a slightly other way but the point should be the same.



来源:https://stackoverflow.com/questions/11772980/include-header-file-in-xcode-c-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!