Framework Issues

Member
Posts: 215
Joined: 2008.06
Post: #1
I'm building some custom objects that I would like to include in a framework so I can easily add them to a project. I created a new XCode project and selected framework. I made my first object, built it, and found the file in the finder. But when I add it to my resources in another project, it contains no files and the compiler refuses to acknowledge it even exists. Is there something I am missing?

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Moderator
Posts: 3,552
Joined: 2003.06
Post: #2
I'm a little hazy on your description. Some more details would be helpful.

One thing I can say right off the top is that it isn't usually good enough to simply include a built framework into another project, you will have to add a "copy files build phase" to make sure said framework is copied into the app bundle.
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #3
AnotherJake Wrote:I'm a little hazy on your description. Some more details would be helpful.

One thing I can say right off the top is that it isn't usually good enough to simply include a built framework into another project, you will have to add a "copy files build phase" to make sure said framework is copied into the app bundle.

Alright, sorry about the ambiguity. I will attempt to restate more clearly: I am building some utility classes that I intend to use in a (or more) future game project(s) and would like to include them in a framework so that I can just copy the framework into the project group instead of having to find each file and then copy each of those into the project.

So, I opened Xcode and began a new Framework project. I wrote my desired class, made sure that building it did not generate any errors, and then checked for the completed *.framework file in it's folder in the Finder.

I found such a folder under /MyProject/build/Debug so I thought that everything was working as expected. I started a new project to unit test my new object and added this *.framework file to the project resources. I also included the #import <MyFamework/MyObject.h> but the compiler said the given file did not exist. Upon opening the contents of this framework folder it contained nothing.

I am wondering if there is something else I need to do to properly compile / finish my framework for future use.

In response to your suggestion, I checked the Project>Start New Copy File Build Phase menu and it looks promising. What destination would you recommend? It has the default as Resources. It also provides a checkbox for Copy Only When Installing; should I check that or not?

Thanks for the help, I hope that clears things up!

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Member
Posts: 508
Joined: 2002.05
Post: #4
I'm still new to this library linking stuff but I changed the copy file build phase to the "Frameworks" folder, and my game has been running fine on computers without the framework installed
Quote this message in a reply
Moderator
Posts: 3,552
Joined: 2003.06
Post: #5
Don't know for sure what is causing the problem, but here are some ideas:

- (sounds like this might be why you aren't seeing anything in your framework) In your framework project, make sure the project view is selected (not debug), click on the target. In the upper right pane should be a list of files in the project. One of the columns there is called "Role". Make sure that all of the headers you want to export are set to "Public" in the little pop-ups. I forget to do this all the time.

- Like Jake already mentioned, when the copy files dialog comes up, just change the destination pop-up to Frameworks and close the window without changing anything else.

- Once you've added a new copy files build phase, you have to drag your framework from where it already is in your Groups & Files, to be under the new "Copy Files" box under your target (click on the disclosure triangle next to the target to see it at the bottom of the list). This will make a copy of it under your new copy files box.

- You can verify that the copy files worked by right-clicking on your built project and showing package contents. Your framework should be in Contents->Frameworks.

- I can't recall if it is a problem or not, but it might be a good idea to build your framework with the release setting. You can still choose to export debug symbols for release, but you will have to specify that explicitly in the target settings.

- In case you aren't aware of this (or forget about it): settings in the target (right-click on target->get Info) override the settings you'd set for the project (right-click on blue project icon).

- When you do make settings, be sure that you have the correct build configuration selected in the info window.
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #6
I followed all of your instructions. The "Add New Copy File Build Phase" seemed to work and now I have a source group called "Copy Headers" that contains my MyObject.h file as well as a "Compile Sources" with my MyObject.m file. This all checks out in the finder as well...

However, when I add the *.framework folder to my unit testing project, I get this error in the console output:

"dyld: Library not loaded: <path to framework>
Referenced from: <path to unit testing project>
Reason: Image not found"

This implies that it cannot find the associated framework, but the compiler allows the project to be built and ran without issue. The application crashes with the above message and an exit code of 5. Any insight?

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Moderator
Posts: 3,552
Joined: 2003.06
Post: #7
The "copy headers" build phase came from you changing the file role of each header you exposed to be public, not the "copy files" build phase.

It sounds like you did the copy files thing in the wrong project. You need to do the copy files build phase in the project that is *using* the framework, not the project where you make the framework itself. That is, the *test application* needs that framework to be copied into the Frameworks directory in its app bundle so it can find it after it launches. That's why you got the "Image not found" message. That's always my first clue that I forgot to do the copy files. Like I said, you can verify that it's there or not by opening the test app's package contents and looking in Contents->Frameworks.

Honestly, it's pretty confusing to figure out how to get it working at first, so don't feel bad. Once you figure out the magic Xcode incantations it's easy though.
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #8
????? That's seems ridiculously round about and, frankly, poorly designed. I should be able to click "Build" and it should generate a framework file that I can drag and drop into a project like the other Apple-provided frameworks.

Thanks for your help, much appreciated. I never imagined that it would be this hard to make a framework. It almost seems more worth it to just create a simple folder to hold my custom files and just drag and drop as needed.

Well, thanks again. I will have to try messing about with it for a short while. All the best.

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
⌘-R in Chief
Posts: 1,171
Joined: 2002.05
Post: #9
Talyn Wrote:????? That's seems ridiculously round about and, frankly, poorly designed. I should be able to click "Build" and it should generate a framework file that I can drag and drop into a project like the other Apple-provided frameworks.

If you want to force your users to install the framework file separately in the Library folder, then you can do so. But if you want your app to be entirely self-contained, then you need to include the framework in the built application's bundle, which is what the copy phase does.
Quote this message in a reply
Moderator
Posts: 3,552
Joined: 2003.06
Post: #10
Yeah, it's a little goofy, but you'll get it working -- it's not hard, just confusing at first. You're on the right path though. Don't worry, it'll work. I do my own custom frameworks all the time now, for the same reasons you're doing it.

You make your custom framework in your framework project. That's easy to understand, no problem.

Then you make a program which makes use of your custom framework. That's easy to understand too, no problem.

The rub happens when you have to make that custom framework available to your app. Either you install it separately in a central location, or you gotta package it up in your app's bundle (as FreakSoftware pointed out). There's no way around this on any system. You will almost always (99.9% of the time) want to package it up with your application. The only crappy part IMHO, is that Xcode doesn't make it very apparent as to how this is done.
Quote this message in a reply
Moderator
Posts: 3,552
Joined: 2003.06
Post: #11
Hey, I just remembered this old video on embedding Cocoa frameworks which you will no doubt find highly useful:

http://rentzsch.com/share/embeddingFrameworks.mov

The page for that is:

http://rentzsch.com/cocoa/embeddedFrameworks

This is for an older version of OS X. Be sure to skip the "first thing" part about the installation path "@executable_path". Skip the prebinding thing too -- don't need -seg1addr anymore. Start paying attention to the "third thing we need to do" with exposing the headers, which is somewhere around a third of the way through.

I wonder if there is a newer video or tutorial around for this stuff?

[edit] Oh yeah, I don't need the project dependency thing anymore either, since I think it was Tiger when Xcode was able to detect that the files had changed... Don't recall exactly though...
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #12
AnotherJake Wrote:Hey, I just remembered this old video on embedding Cocoa frameworks which you will no doubt find highly useful:

http://rentzsch.com/share/embeddingFrameworks.mov

The page for that is:

http://rentzsch.com/cocoa/embeddedFrameworks

This is for an older version of OS X. Be sure to skip the "first thing" part about the installation path "@executable_path". Skip the prebinding thing too -- don't need -seg1addr anymore. Start paying attention to the "third thing we need to do" with exposing the headers, which is somewhere around a third of the way through.

I wonder if there is a newer video or tutorial around for this stuff?

[edit] Oh yeah, I don't need the project dependency thing anymore either, since I think it was Tiger when Xcode was able to detect that the files had changed... Don't recall exactly though...

VERY helpful, thank you! I'm going to have to look around for more tutorials like that (especially on InterfaceBuilder)! I still maintain that is a ridiculously round-about way of doing things. It seems like much less hassle to simply drag and drop the source files into the project and select the "Copy files into project folder" checkbox. Thanks again for the help, I'll be sure to let you know if I run into anything else. All the best.

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Luminary
Posts: 5,125
Joined: 2002.04
Post: #13
Setting the install_name of the framework to @executable_path/../Frameworks is still necessary if the framework is to be embedded.
Quote this message in a reply
Moderator
Posts: 3,552
Joined: 2003.06
Post: #14
Oops, yeah, my bad...
Quote this message in a reply
Post Reply