Project that builds both framework for OS X and static library for iOS - xcode

I am trying to build a library of code that can be built into a .framework for OS X as well as a shared library for iOS. I'm not sure this is possible, there seems to be some strange behavior on XCode 3.2.5's part.
I want one project that holds all my shared code. Keeping the #if and #else definitions out of the equation here, I'd like this code to be able to be built with the 10.6 SDK as well as the iOS 4.2 SDK. I'd like to have 2 separate targets in my project, one building the .framework, and the other building the shared library lib*.a. They would each only get to compile the code that is relevant to them, but this single project would hold all of it.
My first steps seemed ok - created a fresh new project for building .frameworks, then I added a target to build an iOS shared library. As soon as I flip back to the .framework target, I get an error trying to build:
"target specifies product type 'com.apple.product-type.framework', but there's no such product type for the 'iphonesimulator' platform"
I didn't change the "product type" in the framework target (not even sure how), but it now seems to think that it's supposed to build everything for iphonesimulator, and that product doesn't support frameworks (which indeed it doesn't).
Has anyone else gotten this to work? Is this possible with XCode 3.2.5? Will this be possible in XCode 4?

Related

Linking dual (iphoneos and watchos) frameworks with same product name

I recently had to duplicate my own frameworks to be able to link them from the native watchOS 2 extension, because the platform is different. So for every framework X I have an X-watchos counterpart.
Everything works fine in the simulator and when building directly to my devices, and it wasn't until I tried to archive that I got this linking error:
I ran lipo -i on the built watchOS framework and sure enough, its archs are arm7 and arm64 instead of armv7k.
When I looked further into the built directory I noticed this:
Both versions are symlinks to the same file, and because the have the same product name, they're being overridden. I could make them have different names, but that would make importing them really cumbersome.
Note that this is not a problem for 3rd-party frameworks because Carthage is already building them in separate directories.
EDIT 08/22/2015: I've filed a radar with a sample project: http://www.openradar.me/22392501
EDIT 08/24/2015: This has been acknowledged in Xcode 7 Beta 6 release notes as a known issue:
EDIT 09/9/2015: Xcode 7.1 Beta release notes hint that this is fixed, but I haven't confirmed it yet.
This is working for me in Xcode 7.1.
I’m using a similar configuration with my own frameworks, but I set a different name when creating it in each platform (MyFramework and MyFramework-watchOS). Don't forget to set a common product name manually (mine is MyFramework on both) in the build settings tab of each framework.

Framework Not Linking in XCode 4.5

I added the iAd framework to my app, which has two targets. I am able to compile and run one of my targets, but the other does not compile. (The code that doesn't compile in one case does compile in the other case.) Apparently, the framework is not recognized or linked.
I checked the linked libraries in Build Phases for both targets, and the framework is listed. Most of my other libraries were added before I split off another target, and I didn't have this problem for most of them. I recall having something like this happen once before, where I went back into build phases and removed and re-added the framework. That resolved the problem. (I don't remember exactly what I did that one time, though.) I tried this again, and it still does not work.
What can I look for to see what is happening and how I might fix it?
I'm compiling for a target with iOS 5.0 using SDK 6.0.
Make sure your iAD framework is set as a member for the second target.
In other words, look at the file inspector for your iAD framework and make certain the checkmark is checked for both targets.
Here is what it looks like just for a .m file... it would be the same case for the framework:

Xcode 3/4 Compatibility when referencing static libraries

We have multiple development machines, some running Xcode 3.2.5 and others running Xcode 4.2. We have a static library that is referenced by our project. It contains Objective C categories, so we need to use the -force_load flag with the path to the library.
The problem that we are having is that on Xcode 4.2, the library is linked from a different location than the path that we specified in -force_load. This causes duplicate symbol errors since it's trying to link two copies of the same library.
The path Xcode 4.2 links from is:
/Users/USERNAME/Library/Developer/Xcode/DerivedData/PROJECTNAME-ehxeazvigqrpvogkxlkcmdzpisdw/Build/Products/CONFIGURATION-PLATFORM/
whereas the location that Xcode 3.2.5 links from is:
PROJECT_ROOT_OF_STATIC_LIBRARY/build/CONFIGURATION-PLATFORM/
Is there a way to get Xcode 4.2 to use the same locations as Xcode 3.2.5 when linking static libraries so that we can use the force_load linker option? If not, can anyone suggest an alternative solution to get Xcode 3.2.5 and 4.2 to play nicely together?
It sounds to me like you are doing things the hard way.
I've never used -force_load to load static libraries. With the libraries I use, they are all stored as frameworks in a directory on my system which is separate from the project. I then use the XCode standard add frameworks dialogs to bring them into the project and "-ObjC -all_load" to ensure they work and categories are active.
I've successfully move a few projects from XCode 3 to 4 and not had the problem you are mentioning. I suspect that if you can stop using -force_load your problems will go away.

Creating a library (.a) in Mac OS X and Xcode

I'm in the process of porting some code from Linux to Mac OS X. The code is a static library that you add to your code. Basically after you compile the code you get a MyLib.a that can be linked to whatever project you want.
I'm managing the "project" via a Makefile.
Is there a way to have a project on Xcode that ultimately produces the same kind of library? How?
Thank you for the help.
Sure. You don't say so, but I am assuming you are using C or C++ as source.
Assuming you are using Xcode 3.2.2, you can create a new project (File > New Project...), which will bring up a New Project window with available project templates. Select the "Framework & Library" category under Mac OSX from the list on the left. You should now see a "BSD C Library" and "STL C++ Library" among the other library and framework types. For building a static library like you described you want the "BSD C Library" option. There are static and dynamic options for this which you will see when you click on the icon, but static is default.
Depending on which version of Xcode you are using, the location of the project template may be a little different since Apple has been changing this UI for the New Project window fairly frequently. So if you are not using 3.2.2 you may need to poke around the available projects a little bit.
Oh, and don't worry if you are trying to build C++. Event though this says it is for C, C++ libs build just fine as well.

"Relative to Current SDK" doesn't work mixing Mac Framework and iPhone static library

I have a framework of code I maintain. It's got mac and iphone objective-c code. And some of it is shared. I'm not having any problems with code. It's a problem with Xcode.
Let's just call my framework "AwesomeKit" for this problem.
The first thing I did was create an xcode Framework project called "AwesomeKit". Add source files to it, link against the common mac frameworks: foundation, cocoa, carbon, etc. It compiles fine.
Then, add a new "static library" target, let's call it "AwesomeKit-iPhone" and set the base SDK in the build settings to iphone device 3.1.3.
The problem comes when I try to add "Existing Frameworks" to the AweseomKit-iPhone target.
First change the current build target to AwesomeKit-iPhone.
Right click on any group and select "Add > Existing Frameworks..."
Choose UIKit.framework
UIKit will immediately be highlighted red, as if it's missing. It is indeed missing because Xcode uses the "Relative SDK" setting from the "Mac OS 10.6" SDK. When it should be using it relative to the current target's base sdk iphone device 3.1.3.
What the heck? Has anyone experienced this? This is really annoying.
I found the solution to this. You have to edit the project.pbxproj file inside of the project.xcodeproj directory. Find any entries like "SDKROOT = XXX" and change it to you real base root. It's probably best to look another project.pbxproj file that has it correctly set. I've used this on multiple occasions now and works like a charm. Usually there's 2 or more of the SDKROOT entries in project.pbxproj.
I think I've seen your problem. I'm still new myself to this, but what I've found when universal static libraries for both simulators and devices is that it's best to keep the Xcode Active SDK set to "Base SDK" rather that selecting an SDK. IN that mode, the current SDK is the SDK of the currently selected target.
Active SDK is rather like overriding the sdk on the command line. If yoy set it, SDK settings on targets will be overridden.
So im my case I wanted two targets to be run at the same time, one using the simulator sdk which compiles for i386 architecture and the other pointing at the device sdk which builds a universal lib for armv6/armv7 architectures.
I have seen the red not found stuff and I seem to remember that doing this, made it go away. I also had the project SDK set to a device rather than Mac. Remember that targets override this so it's a good way to ensure that Xcode is pointing at the right sdk without effecting the settings on targets and the ultimate build.
I'm in the same boat right now, XCode keep tacking the wrong SDK in front of the frameworks. This is project with both OSX and iOS targets. But there's seems to be something really wrong with my Project Build settings. Your screenshots don't show them, but you may want to check them. In my case, many entries are duplicates. So I have two categories "Architectures", totally identical. If I change one, the other changes along with it. This could be related to the problem with the wrong SDK being chosen. I think the project file is corrupted, and I'm now trying to figure out if I can fix it manually.

Resources