Xcode 6 static library project - xcode

I have a static library project included to my main project.
I followed this tutorial. It worked when I had Xcode 5. It stopped working after I updated to Xcode 6. What might be a reason? I use CocoaPods 0.35.0.

When using Cocoapods, you should not set "Other Linker Flags" manually. This is automatically set as part of the pod install process.
Part of the Tutorial that you linked to tells you to set the Other Linker Flags manually.
Go to your project and clear Other Linker Flags value on the project level and the target level (if it is in bold) by highlighting the value and hitting delete.
Once deleted, you should see the inherited value coming from the Pods.xcconfig file. Something like:
-ObjC -framework CoreGraphics
You can verify this by clicking on "Levels" to the left of the search bar.
This should have you cocoapods libraries sorted. Once this is working add the path to your static library headers by setting "Header Search Paths" to "${inherited} /path/to/static/libary/headers"

Related

Include Headers from added frameworks on 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.

How to add Core Foundation framework in Xcode 4 to a bare Command Line Tool if frameworks list is empty?

I created a new command line tool (the way to create a Mac OS X command line app) using Xcode 4.5, but I now want to add a framework to it. The frameworks list in the build phases is empty.
I can add .h/.m objective C class header and implementation files that I have written but I don't know how to make a "Command Line Tool" into what the old Xcode probably had a different template for; A command line application (not Cocoa app) which can access Core Foundation framework, or any other framework I choose to add to it.
Also, there used to be a "Core Foundation Tool" option in Xcode 3, where is it now?
(Update: I was clicking "+" inside Target Dependencies, which seemed sensible, but which gives me only an empty list of things to add. I figured there must be something somewhere else you had to change to make things show up in Target Dependencies, which if I may say, is not exactly clear to new users. Thus this public service message, question, and answer.
Hey Apple, how about you change this to "Link libraries or Frameworks" so that the word Framework shows up there. Making us guess if we're adding a library or a dependency when the only word we know about is Framework, is confusing.)
Go to the "Link Binary with Libraries" option and click +. It's found on the Build Phases page of your main Xcode project settings. You might want to collapse the Target Dependency and Compile Sources sections, so that the Link Binaries section is fully visible on your screen.
Footnote:
My mistake was clicking "+" in the Target Dependencies section, which was where I thought I might "add a dependency on CoreFoundation", which isn't what you do. I also found it confusing that you Link Binary with Libraries, when I thought that Xcode didn't use Framework and Library terms interchangeably, and in this case, confusingly. It also doesn't help that the plus icon is hidden and you have to scroll to access it, or else collapse the two top sections. Xcode is full of "User Interface is very confusing" areas, in my opinion:
Also, add #import <CoreFoundation/CoreFoundation.h> to your implementation (.m) files, as needed.

Xcode referencing old/removed frameworks, causing multiple interface declarations

I'm getting interface re-declaration errors when I'm trying to build because xcode keeps referencing these old frameworks and headers that I've already removed from the project. I've sifted through my build phases and build settings and nothing seems to point to those files.
The funny thing is when xcode shows me my error and the line of code where the interface is supposedly redeclared, it won't show me any specific file when I click "Show in project navigator". However, if I ask it to "Show in finder", it instantly locates the file in my actual project directory (not xcode project directory). So this means that XCode is picking up unwanted frameworks that I've left in my project directory. I don't want XCode to do this. How do I clean this up? I've tried cleaning, restarting xcode and rebooting.
I looked at another SO discussion with the same problem but the user didn't give a proper solution (http://stackoverflow.com/questions/11759444/xcode-referencing-old-framework). How does one go about disabling the automatic framework searching?
Just in case: have u checked FRAMEWORK_SEARCH_PATHS ? (Project Build Settings). I had a similar situation and found there references to the old paths which I removed and that did the trick.
ADDITION:
As I moved my Xcode-Project to another location the compiler complained about "Library Search Paths" which where pointing to the old location.
See => Build Settings, "Library Search Paths".

Adding a static library to an XCode console application

I'm having trouble adding a static library from another Xcode project (CloudApp API) to my Xcode project. My project has two targets -- a prefpane bundle, and a console application. I want to add the static library to the console application. Here's what I've done so far:
Created a new workspace
Added the CloudApp project to my workspace
Added the libcloud.a file to my "Link Project Binaries" list for the target binary
Added -ObjC to the "Other Linker Flags" setting for the target binary
Added $(BUILD_PRODUCTS_DIR) to the "User Header Search Paths" setting for the target binary
Copied all the relevant headers from the CloudApp project into my project (without adding them to the target) so that I don't get errors from any #import statements
Edited the scheme for the target binary to require compiling CloudApp first
Added relevant frameworks to the target (Cocoa, Foundation, CoreFoundation)
Doing all this worked fine when I just had a single Cocoa target (not a console application). But now I'm getting errors in the CloudApp header files I included. Basically things like this:
In CLWebItem.h:
Unknown type name 'NSImage'
Any ideas?
Create a prefix-header.pch and #import <Cocoa/Cocoa.h> inside. Make sure to compile the prefix header in your settings.

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