PDA

View Full Version : Xcode 4: Adding a Library dependency in a project inside a workflow




Soulstorm
Apr 2, 2011, 01:21 PM
This new way that XCode 4.0 handles dependencies frustrates me.

What I want to do is to have a project that has as a dependency a framework. And I want the resulting .framework file to be copied into the actual executable. In Xcode 3 this was a simple procedure, but now, I can't do it with XCode 4.

I create a new workspace. I add the Application Project. I then drag and drop the Framework's project file underneath the Application Project inside the workflow navigator. I select the Application Project's target, and I add as a dependency the framework. I also Link it with this library.

Now, if I build the Application project it will run just fine, but the .framework file is not included in the application bundle which means that when it is being transferred into another location it will not open!

I remember in XCode 3 that there was a copy files build phase that allowed copying the frameworks with the executable. In XCode 4, I can't select the framework file to add it into the copy files build phase!

Please help me, this is an important problem for me.



jiminaus
Apr 2, 2011, 07:14 PM
I took me a while to figure this one too.

You need to drag the .framework from the Project navigator to the Copy Files build phase, instead of trying to add it to the Copy Files build phase directly using the + button.

Soulstorm
Apr 3, 2011, 02:42 AM
That will indeed copy the framework BUT it won't link only the copied framework.

When I do this, the actual executable is build inside the same folder "Debug" with my framework in the same folder. The framework exists also inside the application bundle! If I delete any of the two, either the one that is inside the application bundle, or the one that is in the same folder as the application bundle, the application crashes complaining it can't find the framework.

I suspect it has something to do with my build configuration but I haven't located the problem, yet.

Please can you point me in the right direction?

EDIT: Strangest thing: If I run the app using the Finder and not XCode, the application crashes again saying that it can't find the library file. Running it using XCode seems to work fine. What does this mean?

jiminaus
Apr 3, 2011, 03:35 AM
That will indeed copy the framework BUT it won't link only the copied framework.


I had to add a run script build phase with the following:


/usr/bin/install_name_tool \
-change \
/Library/Frameworks/MyLib.framework/Versions/A/MyLib \
"@executable_path/../Frameworks/MyLib.framework/Versions/A/MyLib" \
"$CONFIGURATION_BUILD_DIR/$EXECUTABLE_PATH"


But I'm thinking that I don't know how to do this. This seems wrong. There's no target dependency between MyLibTest app and MyLib framework. MyLibTest is linked explicitly to the debug version of MyLib, even we MyLibTest is build for release. This all seems too low level. I feel that I'm doing things XCode should be doing for me.

klaxamazoo
Apr 3, 2011, 07:06 PM
I had a similar issue trying to get the DataGraph framework into my project last week. I made some modified instructions (see attached) from a really good tutorial for Xcode 3.

http://wiki.remobjects.com/wiki/Linking_Custom_Frameworks_from_your_Xcode_Projects

Soulstorm
Apr 4, 2011, 04:38 AM
I had a similar issue trying to get the DataGraph framework into my project last week. I made some modified instructions (see attached) from a really good tutorial for Xcode 3.

http://wiki.remobjects.com/wiki/Linking_Custom_Frameworks_from_your_Xcode_Projects

That's great, but the problem is that I want to have a project reference inside the other one, so that I can modify my library and then build a test application using it.