1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Xcode 4: Adding a Library dependency in a project inside a workflow

Discussion in 'Mac Programming' started by Soulstorm, Apr 2, 2011.

  1. macrumors 68000

    Soulstorm

    #1
    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.
     
  2. macrumors 65816

    jiminaus

    #2
    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.
     
  3. Soulstorm, Apr 3, 2011
    Last edited: Apr 3, 2011

    macrumors 68000

    Soulstorm

    #3
    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?
     
  4. macrumors 65816

    jiminaus

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

    Code:
    /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.
     
  5. macrumors 6502

    #5

    Attached Files:

  6. macrumors 68000

    Soulstorm

    #6
    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.
     

Share This Page