kstenerud / iOS-Universal-Framework

An XCode project template to build universal frameworks (arm7, arm7s, and simulator) for iOS / iPhone.
2.95k stars 473 forks source link

Framework being ignored #80

Open nazilliefesi opened 11 years ago

nazilliefesi commented 11 years ago

First of all thanks for the good work.

I have an SDK product consisting of several(currently 18) static libraries. These libraries are fat static libraries which have been built and then combined(with lipo) for armv7 and i386. They are all written in C++ and they are pretty stable under windows, linux, android,...

Only two of these libraries are directly used by the customers, the remaining libraries are used internally. The libraries' API is very well defined and I do not wish to add extra code to them. But I may, if there is a need to do so for preparing a framework.

My aim: I want to distribute this SDK to our customers in an iPhone-like way. So instead of distributing headers and static libraries seperately I want to distribute a single framework. (I think this is a common aim of many people here) But while doing this I do not want to change the project files of my all libraries. I just want to distribute their outputs.

What I did: Fake framework seemed like the appropriate project type for me so I went and added all the necessary headers to "Copy Headers(Public)" and libraries to "Link Binary with Libraries" in a Fake Framework project. I Removed the arvm6 target from the Valid Architectures and added i386 At this step the framework gave an error complaining that there are no source files to compile. So I added a Dummy.cpp which is practically empty. In order for my own static libraries not to be stripped away I added -all_load to linker flags. Now the build succeeded and I checked the framework. It seems in pretty good shape. * Necessary headers have successfully been copied to Headers folder under the framework. * I checked the framework binary inside the framework folder with commands "nm -arch i386 frameWorkName" and "nm -arch armv7 frameWorkName" . This contains symbols from all the libraries I have linked with.

Then I tested the framework using an app which has been previously directly linked to the static libraries inside the framework. * First it could not find the Headers although I can clearly see them in XCode if I expand the Framework contents. * Just to check the binaries as a temporary workaround I added the full path of the Header folder inside the framework. Now it compiles but gives unresolved symbol errors.

I have tried the scenarios above both with the latest stable version and the beta branch each time creating a new project and taking the steps one by one. I have tried removing and adding the embedded and the other framework. For each change I've gone and deleted the previously used onen, restarted Xcode, and added the new one. I tried adding "-framework frameWorkName" to the project settings. I had already seen my framework's name on the build lines anyway but still gave this a shot. Also I frequently close XCode, clean all the build outputs and then open XCode again. So I do not think I am being troubled by an XCode bug.

Everything seems good but it just does not work. Although I tried reading all your comments and documentation am I missing a simple point . May I kindly take your suggesstions on the issue?

Regards

kstenerud commented 11 years ago

This is actually related to an issue I'm trying to resolve (and the whole reason why Mk 8 is not out of beta yet).

It seems that under certain circumstances Xcode won't trigger builds on deep project dependencies. For example, if you have an app project that depends on a framework project, which in turn depends on a library project, you get the following curious behavior:

So far, the only solution I can think of is to make the universal framework script recursively read dependent project files and try to figure out the correct build(s) to trigger, but it's very tricky to do this and Xcode tends to get in the way.

nazilliefesi commented 11 years ago

Hello, Thanks for the quick response. My Fake Framework project does not have any project dependencies. Our static libraries are seperately built with XCode and I have all the necessary binaries ready. I just added static binaries to the Fake Framework Project. I checked the contents of the output of the Fake Framework project. The headers and the necessary linker symbols are all seem to be there. So it seems like there is no problem with the framework build.

The app also does not depend on the Fake Framework. I just added the Fake Framework output to the app. But the App simply cannot find anything inside the Fake Framework.

nazilliefesi commented 11 years ago

Sorry I am new to Github and closed the issue by mistake. Reopened it now.

nazilliefesi commented 11 years ago

I am still looking for a solution to this problem. Any ideas?

kstenerud commented 11 years ago

Hi, I took another look and I think the problem is that you're manually adding i386 to the architectures. Xcode will automatically compile for i386 when it compiles for the simulator, so you don't need to add it.

I've added a simple example project that shows how to link in a static library in the examples branch https://github.com/kstenerud/iOS-Universal-Framework/tree/examples

Note that I'm using the beta template for this, as it is a little less quirky when it comes to static library linking.

nazilliefesi commented 11 years ago

I've tried removing i386 from the architectures. When I try to build I got an error as follows:


Build other platform xcodebuild -project /Users/tekmekci/svnMert/SDK/GVZRecognizerSDK/GVZRecognizerSDK.xcodeproj -target GVZRecognizerSDK -configuration Release -sdk iphonesimulator5.1 BUILD_DIR=/Users/tekmekci/svnMert/SDK/GVZRecognizerSDK/build CONFIGURATION_TEMP_DIR=/Users/tekmekci/svnMert/SDK/GVZRecognizerSDK/build/GVZRecognizerSDK.build/Release-iphonesimulator build Build settings from command line: BUILD_DIR = /Users/tekmekci/svnMert/SDK/GVZRecognizerSDK/build CONFIGURATION_TEMP_DIR = /Users/tekmekci/svnMert/SDK/GVZRecognizerSDK/build/GVZRecognizerSDK.build/Release-iphonesimulator SDKROOT = iphonesimulator5.1

=== BUILD NATIVE TARGET GVZRecognizerSDK OF PROJECT GVZRecognizerSDK WITH CONFIGURATION Release === Check dependencies No architectures to compile for (ARCHS=i386, VALID_ARCHS=armv7).

\ BUILD FAILED **

The following build commands failed: Check dependencies (1 failure)

Command /bin/sh failed with exit code 65

I also could not get your sample project to work.

I've built the project named LibsIncluded (it as in debug config when I first opened it) When I build TestApp it failed to find the LibsIncluded framework(because it was written in red under frameworks folder) thus gave me an error on the line

import <LibsIncluded/LibsIncluded.h>

telling that it could not find the header file., Then I edited the schemes of both projects to build as Release. LibsIncluded again built successfully. TestApp this time found the LibsIncluded framework(it seemed as a normal framework under frameworks folder) but I still get the "could not find the header file" error exactly on the same line.

This seems similar to the error I was having in my own project. Was there anything I should have done before building your projects. If not maybe I should seriously start to doubt my XCode installation/settings. My XCode version is 4.3.1. Is there any problem using this version?

Regards Mert

kstenerud commented 11 years ago

The framework library project and app project should be in debug config. I only modified SimpleLibrary to release so that I could manually build a fat static library. I've already included the fat binary version of SimpleLibrary in the LibsIncluded framework project so you don't need to do that step. All you need to do is hit the build button.

Basically, LibsIncluded and TestApp should build right out of the box with no modifications. If after a fresh checkout it is getting errors, then there may be a problem with your Xcode installation. Try reinstalling.

Also note: The example projects are using the beta Mk 8 template, so if you want to build LibsIncluded as a standalone framework, you select LibsIncluded and iOS Device as the scheme, and then select Archive from the Product menu. It will pop up the folder containing the finished product once it's built.

nazilliefesi commented 11 years ago

First thing I tried was hitting the build button actually but it did not work. Maybe XCode really is the culprit. I will try to look into this again in monday and post the results. thanks.

nazilliefesi commented 11 years ago

After a fresh checkout it did not work. But after building LibsIncluded I've readded LibsIncluded in the "Link with binaries" section of TestApp and it worked. I will try doing the same to my own framework.