包含来自 Xcode 上添加的框架的标头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15536379/
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-09 04:46:17  来源:igfitidea点击:

Include Headers from added frameworks on Xcode

xcodemacosframeworksglewcg

提问by Itzik984

I want to work with some frameworks like glewand cgso i manually added

我想使用一些框架glewcg所以我手动添加

the needed frameworks to my project by right clicking the project -> Add files to ...

通过右键单击项目 -> 将文件添加到我的项目所需的框架...

and choosing the correct framework. The problem is, when i try to include the header files,

并选择正确的框架。问题是,当我尝试包含头文件时,

Xcode cant find any of them. I hope this picture will help to understand:

Xcode 找不到其中任何一个。我希望这张图能帮助理解:

enter image description here

在此处输入图片说明

And:

和:

enter image description here

在此处输入图片说明

The error given is for the glewframework, but it also happens on Cg.

给出的错误是针对glew框架的,但它也发生在Cg.

As you can see on the left, The needed frameworks were added.

正如您在左侧看到的,添加了所需的框架。

Any idea on how i can include these headers?

关于如何包含这些标题的任何想法?

After trying to add the header files manually i got an architecture error:

尝试手动添加头文件后,出现架构错误:

enter image description here

在此处输入图片说明

I dont know if this is how it should look like. Thanks!

我不知道这是不是应该的样子。谢谢!

回答by Jean

Before starting, remove the framework and all files you have added while trying to make it work.

在开始之前,删除框架和您在尝试使其工作时添加的所有文件。

Then, you have to add the frameworks in the Build Phasesof your target. Then go into Link Binary With Librariesand select your framework from there.

然后,您必须在Build Phases目标中添加框架。然后进入Link Binary With Libraries并从那里选择您的框架。

This should do it. Your headers should be available as auto-completion after each #import directive.If it does not work (it sometimes happens), there are additional steps I can provide to you.

这应该做。您的标题应该在每次之后自动完成#import directive.如果它不起作用(有时会发生),我可以为您提供其他步骤。

Additional steps:

附加步骤:

Go to your project settings, in the build settings:

转到您的项目设置,在构建设置中:

  • Complete the Framework Search Pathswith the path of your framework
  • Do the same with User Header Search Path
  • Framework Search Paths用你的框架路径完成
  • 做同样的事情 User Header Search Path

Then, it should work. If it does not, you will need to add the full path of your header in the #importdirective. Example:

然后,它应该工作。如果没有,您将需要在#import指令中添加标头的完整路径。例子:

#import "/path/to/my/header.h"

#import "/path/to/my/header.h"



Apple's documentation available here states:

此处提供的Apple 文档指出:

  1. In the project navigator, select your project
  2. Select your target
  3. Select the 'Build Phases' tab
  4. Open 'Link Binaries With Libraries' expander
  5. Click the '+' button
  6. Select your framework
  7. (optional) Drag and drop the added framework to the 'Frameworks' group
  1. 在项目导航器中,选择您的项目
  2. 选择你的目标
  3. 选择“构建阶段”选项卡
  4. 打开“使用库链接二进制文件”扩展器
  5. 单击“+”按钮
  6. 选择您的框架
  7. (可选)将添加的框架拖放到“框架”组

回答by CAMOBAP

In my case I have added Framework Search Pathsfor Target, but it should be added to Project

在我的情况下,我已经Framework Search Paths为 Target添加了,但它应该添加到Project

enter image description here

在此处输入图片说明

Also Always Search Users Pathshould be yes

Always Search Users Path应该是yes

回答by Kiran

For those whose autocomplete fails after adding framework.

对于那些在添加框架后自动完成失败的人。

I used to add frameworks, by going to Build Phasesand taking the Link Binary with Librariesoption. Now in XCode 6.1, though project was building fine, autocomplete in XCode was not working.

我过去常常通过转到Build PhasesLink Binary with Libraries选择选项来添加框架。现在在 XCode 6.1 中,虽然项目构建良好,但 XCode 中的自动完成功能不起作用。

So what needs to be done is:

所以需要做的是:

  1. Remove the already added framework from Project Navigatorand also from Link Binary with Libraries.
  2. Add framework to project by simply File-> Add Files tooption in XCode.
  1. Project Navigator和 中删除已经添加的框架Link Binary with Libraries
  2. 只需在 XCode 中通过File->Add Files to选项将框架添加到项目中。

And auto complete will start working.

并且自动完成将开始工作。

回答by Egil Sandfeld

In my case, the external framework had been downloaded with Windows and added to the project. Then it was transferred to OSX, where the Xcode project was built and the external framework didn't load properly. I guess it is because Windows changes the framework folder to be a regular folder, which OSX then has trouble with.

就我而言,外部框架已随 Windows 一起下载并添加到项目中。然后它被转移到 OSX,在那里构建了 Xcode 项目并且外部框架没有正确加载。我想这是因为 Windows 将框架文件夹更改为常规文件夹,然后 OSX 遇到了麻烦。

Solution for me was to simply download the framework with OSX and drag it into the framework folder in the XCode project.

我的解决方案是简单地使用 OSX 下载框架并将其拖到 XCode 项目中的框架文件夹中。

回答by ofirbt

In my case I had to update a framework version, so I just replaced the .framework in the filesystem and then I got the error you've mentioned in the question.

在我的情况下,我不得不更新框架版本,所以我只是替换了文件系统中的 .framework ,然后我得到了你在问题中提到的错误。

Removing the framework and adding it back again, playing with the search paths and all the other suggestions didn't help.

删除框架并重新添加它,使用搜索路径和所有其他建议都没有帮助。

Eventually, cleaning the build folder did the trick:

最终,清理构建文件夹成功了:

Select "Product" from the xcode menu, hold the option key and click on: "Clean Build Folder".

从 xcode 菜单中选择“产品”,按住选项键并单击:“清理构建文件夹”。

After that I built and ran the project successfully.

之后,我成功构建并运行了该项目。