Linking a static library to an iOS project in Xcode 4

后端 未结 6 1813
醉酒成梦
醉酒成梦 2020-11-28 02:16

I have a project (AQGridView) that compiles to a static library, but I can\'t seem to add it to my project.

Dragging in the project to my project create

相关标签:
6条回答
  • 2020-11-28 02:27

    Follow Apple's documentation.

    In brief:

    1. Link your target against the library.
    2. Add -ObjC to 'Other Linker Flags' (OTHER_LDFLAGS) under the target's build settings.

    Also, I needed to add the library to the scheme of my main project since the library was not visible in the target's dependencies.

    0 讨论(0)
  • 2020-11-28 02:30

    Find your .a file in finder, and drag it into your project.

    Select the 'copy items into destination group's folder (if needed)', and add your headers to your project.

    Now, XCode 4 should automatically link against that framework for you.

    Here is what the library should look like in your project:

    0 讨论(0)
  • 2020-11-28 02:36

    I do this as follows:

    1. Drag in the static library project. If you have the static library project open in Xcode, close it now.
    2. Select the main project in the project navigator (the project I'm adding the static library to) and in the editor, under the header TARGETS in the left-hand column, select my main project's target and navigate to the Build Phases tab.
    3. Click the "+" for Target Dependencies and add the library icon target dependency from the added static library project.
    4. Click the "+" for Link Binary with Libraries and add the library icon that is under the folder "Workspace".
    5. It may also be necessary to enter a Header Search Path for the headers of the static library project if that is how the headers are linked in the static library project itself.

    If you don't see the static library project as nested under the main project in the main project's project navigator, the most likely reason for that is that the static library's own Xcode project is still open. Quit Xcode and open up the main project that has the nested static library project in it without opening up the original static library project itself, and you should see it appearing as a nested project in your main project.

    0 讨论(0)
  • 2020-11-28 02:37

    Workspaces are supposed to make this easier, but I don't know that they do. The way I do it is create a workspace, add my main project, add my library project. Then go into the main project's build phases and add the library in the "Link binary with libraries" section and add the library. That should be all that is necessary, at least that's my reading, but it isn't. What I do is go into Xcode preferences, then to the Source Trees pane. Add a source tree that points to your static library's headers, then go back to the build settings for your project, then to the Header Search Paths key, and enter ${foo} there, where "foo" is whatever you called the source tree.

    That's what works for me, though I don't know if that's the best or easiest way to do it.

    0 讨论(0)
  • 2020-11-28 02:40

    The Halle's answer works for me with one addition:

    1. Check in Build Settings of the static library project the Private( or Public) Headers Folder Path value and copy it.
    2. Add copied value to the client project Build Settings Header Search Path or User Header Search Path depending of the include directive you are using
    0 讨论(0)
  • 2020-11-28 02:48

    Xcode menu > View > Utilities > File Inspector

    Select the static library file, and then set 'File Type' as 'Mach-O object code' in 'Identity and Type'.

    0 讨论(0)
提交回复
热议问题