Xcode #import 找不到 .h 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6039068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:03:04  来源:igfitidea点击:

Xcode #import not finding .h file

objective-cxcodeimport

提问by jag

I'm trying to import a .h file from an old xcode project into my current one. The file location is the same as the other files in the project (I moved it there), but after using #import in my program body file, when I try to run the program I get the following fail:

我正在尝试将旧的 xcode 项目中的 .h 文件导入我当前的项目中。文件位置与项目中的其他文件相同(我将它移到那里),但是在我的程序主体文件中使用 #import 后,当我尝试运行该程序时,我得到以下失败:

"_OBJC_CLASS_$_Fraction", referenced from:

“_OBJC_CLASS_$_Fraction”,引用自:

objc-class-ref-to-Fraction in 9.1main.o

9.1main.o 中的 objc-class-ref-to-Fraction

ld: symbol(s) not found collect2: ld returned 1 exit status

ld:未找到符号 collect2:ld 返回 1 个退出状态

Does anyone know how to fix this? Thanks!

有谁知道如何解决这一问题?谢谢!

采纳答案by willc2

Assuming that you also added Fraction.m to the project,

假设您还将 Fraction.m 添加到项目中,

In the Group & Files view, select Fraction.m

在组和文件视图中,选择Fraction.m

Show the Editor view (Menu-->View-->Zoom Editor Out)

显示编辑器视图(菜单--> 视图--> 缩小编辑器)

Select the Detail tab. There you should (again) see the Fraction.m file.

选择详细信息选项卡。在那里你应该(再次)看到 Fraction.m 文件。

At the far right of the column there is a tiny target symbol. Make sure that column has a checkmark.

在列的最右侧有一个微小的目标符号。确保该列有一个复选标记。

That ensures that your class Fractionis included when Xcode builds the app.

这可确保在 Xcode 构建应用程序时包含您的类Fraction

回答by Rodrigo Rodriguez

It happened the same to me, what I did was this:

它发生在我身上,我做的是这样的:

1.- Click @ the "Show the project navigator" tab.

1.- 单击@“显示项目导航器”选项卡。

2.- Select your program's folder, the same that contains your main file, ie. "Program 1"

2.- 选择您的程序文件夹,与包含您的主文件的文件夹相同,即。“程序1”

3.- In that same tab, go to the left bottom of the screen, there are 4 signs and a search window. Click on the icon on the left, the one with a "+" sign (add a new file).

3.- 在同一个选项卡中,转到屏幕的左下角,有 4 个标志和一个搜索窗口。单击左侧的图标,带有“+”号的图标(添加新文件)。

4.- From the rollup window, select: "Add files to program..." .

4.- 从汇总窗口中,选择:“将文件添加到程序...”。

5.- A new finder window appears, look for the files you want to add, (.h and .m for example) Click the "Add button"...

5.- 出现一个新的查找器窗口,查找要添加的文件,(例如.h 和.m)单击“添加按钮”...

Voila!

瞧!

Note that the files you are adding MUST be in the same folder as your main file, otherwise you'll have problems when compiling.

请注意,您添加的文件必须与主文件位于同一文件夹中,否则编译时会出现问题。

Hope this helps.

希望这可以帮助。

回答by Hamid Vakilian

Go to Xcode Project Settings -> Build Phases -> In Headers Section look for your .h file and move it to Public list.

转到 Xcode Project Settings -> Build Phases -> In Headers Section 查找您的 .h 文件并将其移动到公共列表。