Include Headers from added frameworks on Xcode
Asked Answered
N

5

43

I want to work with some frameworks like glew and cg so i manually added

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:

enter image description here

And:

enter image description here

The error given is for the glew framework, but it also happens on 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!

Natch answered 20/3, 2013 at 22:58 Comment(2)
I had the same issue and fixed it by setting I had to set Build Settings -> Framework Search Paths to $(SRCROOT) (assuming you your frameworks in the root of your project directory).Wofford
For future searches, another potential cause is having a duplicate framework in your project.Hesperides
S
65

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 Phases of your target. Then go into Link Binary With Libraries and select your framework from there.

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.

Additional steps:

Go to your project settings, in the build settings:

  • Complete the Framework Search Paths with the path of your framework
  • Do the same with 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 #import directive. Example:

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


Apple's documentation available here states:

  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
Schnorkle answered 20/3, 2013 at 23:1 Comment(4)
@Natch I have added the additional steps. Are your frameworks located in /Library/Frameworks?Schnorkle
they are under /System/Library/Frameworks is this ok? or should move them there?Natch
@Natch I guess it is OK. But you may need to tell Xcode in which folder are the frameworks and in which folder are the headers. I had a similar issue recently. Xcode wouldn't compile with linked frameworks in /Library/Frameworks like it used to. Actually, it couldn't find the headers. Adding the full path in the #import directive solved it. Later, I added the folder to the User Header Search Paths so I wouldn't need to use the full path.Schnorkle
I just had the same issue and could solve it when setting the search paths to $(SRCROOT) and NON-recursive!!! With recursive auto-complete was not able to find it, but when setting to non-recursive auto-complete find the sub-folder and then the header file.Illation
U
6

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

enter image description here

Also Always Search Users Path should be yes

Unbolted answered 28/3, 2015 at 21:35 Comment(1)
At this time, deprecatedCarrera
W
4

For those whose autocomplete fails after adding framework.

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

So what needs to be done is:

  1. Remove the already added framework from Project Navigator and also from Link Binary with Libraries.
  2. Add framework to project by simply File -> Add Files to option in XCode.

And auto complete will start working.

Wendelin answered 24/3, 2015 at 9:22 Comment(2)
I am trying to include a framework that I built myself. For some reason adding it to a project in the build phases link binary with libraries section doesn't work, but simply adding the framework via add files to project DOES work. Thank you for this. (voted)Bunni
THANK you! This is only solution... Just wonder why it is always so hard to do that obvious things...Johnajohnath
K
3

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.

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

Katsuyama answered 12/1, 2016 at 14:53 Comment(0)
Q
1

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.

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".

After that I built and ran the project successfully.

Questioning answered 12/3, 2018 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.