Include Headers from added frameworks on Xcode - xcode

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:
And:
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:
I dont know if this is how it should look like.
Thanks!

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:
In the project navigator, select
your project
Select your target
Select the 'Build Phases' tab
Open 'Link Binaries With Libraries'
expander
Click the '+' button
Select your framework
(optional) Drag and drop the added
framework to the 'Frameworks' group

In my case I have added Framework Search Paths for Target, but it should be added to Project
Also Always Search Users Path should be yes

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:
Remove the already added framework from Project Navigator and also from Link Binary with Libraries.
Add framework to project by simply File -> Add Files to option in XCode.
And auto complete will start working.

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.

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.

Related

XCode 5.1 crashes when I drag-drop one project into another project's tree

I've created a new "single view" iOS universal app.
I want to link theamazingaudioengine
I'm on step 2 here: http://theamazingaudioengine.com/doc/_getting-_started.html
"Drag TheAmazingAudioEngine.xcodeproj from that folder into your
project's navigation tree in Xcode. It'll be added as a sub-project."
But instead, I'm trying to place it alongside:
To my mind it makes more sense that the project should be next to each other.
However, I can't include the .a as a target dependency. I can't drag drop it. And if I click the +, there is no possibility to include it.
So maybe I am wrong, and I have to do exactly as the instruction says?
So I try to drag-drop "TheAmazingAudioEngine" into the Ultra project-tree, between "Ultra" project and "Ultra" folder.
This crashes Xcode.
It is repeatable.
Should I file a bug, and am I wrong to to place the projects side-by-side?
It crashes for me too if I drag and drop.
Found that by using the Add files to "my project" setting it will work.
When you choose the Add files option, navigate and ONLY add the theamazingaudioengine.xcodeproj file. It will automatically add the whole project. Now you will be able to link.
This issue has been fixed in Version 5.1.1. The update was released on April 10.
https://itunes.apple.com/us/app/xcode/id497799835?mt=12

xcode error Lexical or Preprocessor issue

I am trying to follow this tutorial and am encountering this error. If somebody could help me it would be much, much appreciated.
Thanks.
That header is probably not in your project navigator in xcode, You need to find the file in finder and drag it into xcode and place it in your project navigator
A few options I can suggest:
Add the framework part of the path #import <SMTPSend/NSData+Base64Additions> (also if this is a framework, you should probably use these enclosures: <.../file.h> instead of quotes)
Add the frameworks path to your build settings ( Framework Search Paths )
Make sure the framework is in the Link Binary With Libraries section
Remove the framework reference from the project organizer pane (cmd+1), then drag it back in (refreshes the path for the file)
Clean/Clean Build Folder/Rebuild
Hope one of those helps!

How to make Xcode find file FacebookSDK.h?

It says "FacebookSDK/FacebookSDK.h file not found"
Yet I can jump-to-definition on the #import and it takes me to the file.
And once I added the #import it now knows what FBFriendPickerDelegate is and it now doesn't have an error on that line.
I have the facebookSDK.framework in my project and in the right folder. It's SDK 3.1.
I tried adding search paths to /FacebookSDK and /FacebookSDK.framework and /FacebookSDK/Versions/A/Headers etc. I also tried #import "FacebookSDK.framework/Versions/A/Headers/FacebookSDK.h" and it still says it can't find it. I also tried clean and restarting. I have the latest version of Xcode.
//
// FacebookView.h
//
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#interface FacebookView : UIViewController <FBFriendPickerDelegate>
{
}
First, you have to remove your FacebookSDK.framework from your Project. Then start over again with these 5 steps. DO NOT re-link the framework.
Go to Build Phases in your Project Target.
In Link Binary With Libraries, click the "+" button.
Click on "Add Other..." button
Browse your FacebookSDK folder. Generally in ~/Documents/FacebookSDK/
Clik on (select) "facebookSDK.framework" and then OPEN.
That's it.
No need to remove anything.
In your project go to: "Build Settings”, then “Search Paths". Look for "Frameworks Search Paths". You probably have something fixed like this:
Frameworks Search Paths: /Users/john/Documents/exampleappxyz
Change it to:
Frameworks search paths: $(PROJECT_DIR)
Voila!.
I tried this but it did not work for me. I had to go into the Build Settings for the project and manually fix the FacebookSDK Framework Search Paths to find the FacebookSDK.
Ok guys, I think i got the answer. Follow the steps given below.
Copy your framework into your project.
Make sure it is under some directory. e.g. $(PROJECT_DIR)/project_name/Resources/Frameworks
Click on the target.
Goto Build Phases→Link binary with Libraries
Add the custom framework by clicking "Add Other"
Verify in the project navigator that the framework exists only once.
Now goto Build Settings→Search Paths→Framework Search Path and make sure that it has the following two things.
(a) $(inherited)
(b) $(PROJECT_DIR)/project_name/Resources/Frameworks.
Not to remind the framework exists inside the Frameworks folder
Make sure that there is nothing in the library search path.
Now click on the project (above target)→Build settings and repeat steps 7 and 8.
Now clean the project and build the project.
Hope it works.
Please remember not to keep any folder names with spaces. If you have kept them, make sure that you provide the correct escape characters.
How to remove facebook sdk links:
For those who like myself improperly added the facebook sdk. to remove the facebook SDK from your project,
check the link inside your frameworks folder, delete any facebook sdk link in there
go into Build Phases -> Link Binary With Libraries and delete any facebook sdk in there
Right click on the frameworks folder and select "show in finder" and delete any facebook sdk in there
Now follow "Fede Cugliandolo"'s steps and re add the facebook sdk
I got this problem today.
It turns out I need to have my Framework search path in all three places:
1) Project Build Settings
2) App Target Build Settings
3) UnitTests Target Build Settings
My search path is:
/Users/myusername/Documents/FacebookSDK
After ensure that, the error disappeared for me.
I use xcode 5 and when add sdk it not correct write self address in "project.pbxproj".
Instead local address for sdk it save global address.
I open "project.pbxproj" and finde the places of it and leave address only for sdk in project.
<project name>/src/external/facebook
<project name>/src/external/testflight
to edit the entry was as follows
/Users/<user Name>/myProjects/.../ios/<project name>/src/external/facebook
You have to change the property "Framework search path" in your build settings, and specify where the file FacebookSDK.framework is located (you can then use the SRCROOT variable to point to the root of your project directory, and thus, avoid using absolute paths ;)) e.g. :
$(SRCROOT)/SampleProject/src/Utils/Facebook/
this is normally done automatically by Xcode when you import a third part framework, but it messes sometimes, (eg: when your modify your project directory tree...)
Hope that helps...
besides adding the search path I also had to set the paths to recursive and remove "*.framework" from the "Sub Directories to Exclude" option for this to work.
This happens if you have imported the facebookSDK twice and after having deleting some files.
For example, I imported the facebookSDK in $project/framework but I deleted it for some reasons. Then I imported it via ~/Documents/FacebookSDK but Xcode kept the old folder and search in it by default.
I have to remove all references and files of the old import to resolve my issue.
I ended up checking my project directory, remove any old references to the framework file. Then, remove it from Build Phases/Search paths. Also remove the linked Framework. Restart Xcode, and do the process over again: drag Framework to Frameworks, don't copy in. Check the Build Phases/Search paths. include "#import ". Finally worked. Whew.
Follow the instruction
At step 4 Configure your Xcode Project
I think you missing something. Delete the Facebook.sdk in your project and try again.
I had the same issue when I updated XCode, but in my case I didn't want to make any manual changes to the project settings as I use CMake to create it. You can find the way I fixed it here: https://stackoverflow.com/a/25564152/525873
it is simple, you have to remove your FacebookSDK.framework from your Project.
Go to Build Phases in your Project Target.
In Link Binary With Libraries, click the "+" button.
Click on "Add Other..." button
Browse your FacebookSDK folder.
Generally in ~/mohit/Documents/FacebookSDK/
Clik on (select) "facebookSDK.framework" and then OPEN.
Now copy this Target settings > framework search path into Project setting > framework search path.
None of all answers above worked for me.
What finally did the trick for me was to change the structure of the plugin folder:
Create folder: com.phonegap.plugins.facebookconnect/FacebookSDK
Copy all content from:
com.phonegap.plugins.facebookconnect/FacebookSDK.framework/Headers
to com.phonegap.plugins.facebookconnect/FacebookSDK
Copy com.phonegap.plugins.facebookconnect/Facebook.framework
to com.phonegap.plugins.facebookconnect/FacebookSDK
And finally, change
#import <FacebookSDK/FacebookSDK.h>
to
#import "FacebookSDK/FacebookSDK.h"
The only solution I found was:
Remove the phonegap plugin: ionic plugin rm phonegap-facebook-plugin
Clone the next plugin git clone: https://github.com/jeduan/cordova-plugin-facebook4.git
Add the plugin manually: cordova -d plugin add PATH/cordova-plugin-facebook4 --variable APP_ID="*****" --variable APP_NAME="*****"
Before this a tried to re add FacebookSDK.framework and installed the phonegap plugin facebook through a locally cloned, but the error continues.
Just follow these steps:
Open Xcode's Build Settings tab in your project.
Add ~/Documents/FacebookSDK to the project's Framework Search Paths setting.

How to add Private Framework to Target Dependencies?

I'm trying to embed a private framework (last paragraph) in my application bundle using XCode 4 and following Apple's (seemingly) outdated instructions.
In my case, I'm Using Separate Xcode Projects For Each Target. This is the final step:
In the General tab of the inspector window, add your framework as a dependency for the application. Adding this dependency causes Xcode to
build the framework target before building the application target.
The build dependency you establish in the application target causes the framework to be built before the application. This is important because it guarantees that a built version of your framework will be available to link against and to embed in the application. Because of this dependency, you can set the active target of your Xcode project to your application and leave it there. Building the application now builds the framework and copies it to the application bundle directory, creating the necessary linkage between the two.
Yet, when in click on the + button in Target Dependencies the framework doesn't show up. How can I establish a build dependency between the private framework and the application target in Xcode 4?
Edit: I should clarify that I already got the private framework working. I just want to avoid having cleaning the project every time a change to the framework is made, and make sure the framework is built before the application target.
Managed to solve this by adding the private framework project as a subproject, then adding the framework target in Target Dependencies.
However, in my case the framework target didn't show as an option in Target Dependencies until I deleted DerivedData. That nasty little bug drove me crazy.
If you want to add your private framework without including it as a sub project, you have to add a Copy Files task for it:
Select your framework with the + button and choose Frameworks for Destination.
You don't need to add anything in Target Dependencies.
Also for this to work, make sure Runpath Search Paths value is #executable_path/Frameworks in the Build Settings tab.
Select your project in the Xcode and then you can find the Project and Target at the right side. Then Select Target and go to LinkBinary with Libraries and then one window will come and there at the bottom left there is an option called Add other.
You first need to add the other project's .xcodeproj to the project as a subproject:
Right-click the Frameworks group (or whatever/wherever else)
Select Add Files to "<Project>..."
Select the other project's .xcodeproj
That other project's targets will now appear in the Target Dependencies menu
Here is more complete answer with update for Xcode 12+.
Copy the 3rd party framework to your project folder.
It can be anywhere within the same project in the tree. You will need the path info in later steps.
In Xcode, select your build target, then select "general" tab, scroll down to "Framework, libraries, and Embedded Content", then select "+" to browse and select the 3rd part library/framework you want to add. See bellow:
Once added, make sure "Embed & Sign" is selected at the dropdown list for the library/framework you are trying to add.
This is important since the framework will be looked up and loaded at runtime.
Go to "Build Settings" tab, and find "Framework Search Path", and enter the path to the framework's in relative to your Xcode project file's location. See bellow:
Now you can build and run your app with the added framework.

Three20 v1.1 and Xcode 4

Is there an easy way of getting Three20 v1.1 to work under xCode 4?
I followed the steps on http://three20.info/article/2011-03-10-Xcode4-Support but that seems to be for the master. I use v1.1 as I use the TTLauncher.
The project builds fine with a normal build, and runs perfect on an iPhone.
But when I want to create the archive (for the IPA for distribution) then I get 18 errors and 8 warnings.
The first one is:
../scripts/Protect.command: line 23: cd: /Users/XXX/Library/Developer/Xcode/DerivedData/iDoms-cmyivarwxpbvqdfnyclqdrikrtmw/ArchiveIntermediates/iDoms/BuildProductsPath/Release-iphoneos/../three20/Three20UICommon: No such file or directory
Most others are 'no such file or directory' on e.g.:
#import "Three20Core/TTGlobalCoreLocale.h"
or 'undeclared (first use of function)' which comes from the 'no such file or directory issue I presume'.
In my 'Header search paths' I have:
$(BUILT_PRODUCTS_DIR)/../three20
$(BUILT_PRODUCTS_DIR)/../../three20
../../three20/Build/Products/three20
/usr/include/libxml2
Any help would be very appreciated!
Just to add to Colin's answer: you can use Xcode's dependent projects feature to use three20, even though the three20 website says it's not "officially supported":
In your workspace, right-click on the empty space in your project navigator. Select "Add files to "My Workspace", and select the three20 project (three20/src/Three20/Three20.xcodeproj). This is the only project you need to add: it is not necessary to manually add the three20 subprojects.
Select your project in the navigator, go to Build Phases, open "Link binary with libraries", click on the "+" in the bottom left corner, and add the Three20 libraries: libThree20.a, libThree20Core.a, libThree20Network.a, libThree20Style.a, libThree20UI.a, libThree20UICommon.a and libThree20Navigator.a. This will cause Xcode to build Three20 when you build your project.
Add ${BUILD_DIR}/three20 to your include path as per Colin's answer: go to build settings, double click on "Header Search Paths", and add ${BUILD_DIR}/three20 (it will show as build/three20 when you close the dialog).
Add three20/src/Three20.bundle to your resources.
It's probably also a good idea to add the linker flags -ObjC and -all_load if you haven't already done so (same dialog, setting "Other Linker Flags").
The steps above are good enough for compiling the code. To make "Archive" work too, you will need to:
Add $(BUILT_PRODUCTS_DIR)/../three20 and $(BUILT_PRODUCTS_DIR)/../../three20 to the Header Search Paths setting. If you don't you will get compilation errors that the three20 headers cannot be found.
For all Three20 projects (so not just the top-level project), go the Build Settings and set "Skip Install" to YES. If you don't, the project will build, but you will not be able to create an IPA.
Make sure that your product name (select your target, go to Build Settings, then setting "Product Name") does not contain spaces, otherwise archiving will not work.
Finally, if you're getting errors such as ld: library not found for -lThree20 and you are using a custom build configuration (such as AdHoc), make sure to add the same build configuration to each of the Three20 projects too (just duplicate the Release configuration).
You should check out this StackOverflow question.
I've reproduced the accepted answer below:
So it looks like the easiest way
to get old Xcode 3.2 projects to work
with Xcode 4 is to do the following:
Go into Xcode 4's preferences (Cmd+,).
Select the "Locations" tab. Where it
says "Build Locations", select the
drop down and pick "Place build
products in locations specified by
targets" I'll write up a three20.info
article going into more details about
this.
Add these two paths to your header search paths in the build settings for your target:
"$(BUILD_DIR)/three20"
"$(BUILD_DIR)/../three20"
The first entry is needed for regular builds and the second entry is needed for archives.
It's that easy.
Incidentally, to create a file in your home directory with a list of all of Xcode's environment variables for your target's environement, add the following Run script build phase to your target with contents:
ENV > ~/xcode-environment.sh
Note that in this case, if your project is not making it through the compile phase of the build process, and your Run script comes later, the script won't get executed, so put it first.

Resources