问题描述
我是Xcode子项目的新手。在我的iPhone应用程序项目 MyProject
中,我试图将一些常用代码重构为名为 MyLibrary
的静态库项目。在我创建 MyLibrary
并移动代码后, MyProject
不再编译。错误是 MyProject
无法在 MyLibrary
中看到.h文件。
I am new to Xcode subprojects. In my iPhone app project MyProject
, I am trying to refactor some common code to a static library project called MyLibrary
. After I create MyLibrary
and move the code, MyProject
is no-longer compiling. The error is that the MyProject
cannot see the .h files in MyLibrary
.
错误 MyLibraryConfig.h:没有这样的文件或目录
即将出现:
#import "MyLibraryConfig.h"
- 如何在
MyProject
中导入MyLibrary
.h文件? - 这里的最佳做法是什么?假设我有多个这样的库,将这些库添加到父项目的标题搜索路径是很繁琐的。
- How to import the
MyLibrary
.h files inMyProject
? - What is the best practice here? Assuming I have multiple such libraries, it is tedious to add these to header search paths to the parent project.
推荐答案
也许您的头文件也在子目录中。
Maybe your header file is also in a subdirectory.
想象一下以下目录设置:
Imagine the following directory setup:
- Desktop
- MyProject
- MyProject.xcodeproj
- main.m
- MyLibrary
- MyLibrary.xcodeproj
- MyHeaderFile.h <-- wanted header file
如果 main.m 包含以下内容:
#include "MyHeaderFile.h"
int main() {
return 0;
}
编译器(gcc)会认为 MyHeaderFile.h 与 main.m 位于同一目录中,包含它。要告诉编译器你的意思是子文件夹中的头文件,你可以做两件事。
The compiler (gcc) will think that MyHeaderFile.h is located in the same directory as main.m, from which it is included. To tell the compiler you mean the header file in a subfolder, you have can do two things.
- 你可以在gcc中添加一个目录编译器说:嘿,也看看那个文件夹。您可以使用
-iquote myFolder
标志来执行此操作。 - 您可以在include语句中包含该目录:
#includeMyLibrary / MyHeaderFile.h
- You can add a directory to the gcc compiler that says: "hey, also look in that folder". You can do this by using the
-iquote myFolder
flag. - You can include the directory in the include-statement:
#include "MyLibrary/MyHeaderFile.h"
当然还有其他问题,但这个接缝就像最直接的一样。
There could of course be another problem, but this seams like the most straightforward one.
这篇关于Xcode 4.2:如何从子项目导入.h文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!