Adding OCHamcrest to an IOS Project

1.3k Views Asked by At

The documentation for the project says just add the framework and the linker flags and you are good to go. Hours and hours of wasted time later, I have figured out that that's not true. If you do that, the project does not see the header files. You have to put the framework somewhere were the compiler will find the headers. In my case, that worked when I dropped the framework into /Developer/Library/Frameworks and then told it to recurse in searching that framework directory (do not fiddle around with the headers search directories).

Then the problem I get is that the link fails with the message:

ld: framework not found OCHamcrestIOS

I noticed that the documentation for the project says that it was updated for Xcode 4. I pulled down the binary of the framework after checking out the code and wasting a ton of time unable to build the IOS version of the framework.

The documentation is here.

I also noticed in that documentation that the cocoa instructions tell you to put a copy files phase into the build. I tried that. Didn't change the outcome.

The last time I fell into a sink hole it was because the library was C++ code. Maybe that's still the problem.

Barring a rapid solution here, I am going to go back to using STAsserts, as sickening as that prospect is, this is far, far worse.


Update: reinstalled Xcode. Still doesn't work. There are cheap ways to make this work, like add the header files to the project. Did a blog post about this that brought out a person with the same experience.

2

There are 2 best solutions below

0
On BEST ANSWER

So the solution I adopted for now, after much thrashing around, was to include the framework in the project.

  1. Create a group inside the Xcode project called Third Party.
  2. Link it to a folder called thirdparty.
  3. Go to the Add Files in Xcode and pick the framework.
  4. Drag it over to the dependencies.
  5. Run the tests, they pass!

This is maybe preferable anyway because referencing it in /System/Library/Frameworks would present some versioning issues, and this can be setup very quickly. Furthermore, we have a continuous integration server, and having to get in there and sync versions whenever something changes is not so great.

Thanks for checking it out, Derek.

4
On

I use a number of frameworks in my projects. Some from other people and some are mine. Looking at the documentation I would suggest that the copy phase stuff is not for iOS development. So I would not do that. I downloaded the latest zip from https://github.com/jonreid/OCHamcrest and it appears to contain a ready to go iOS static library. (Not on my mac so I cannot test to confirm).

Anyway, the way I include static libs is to

  • Select the project (XCode 4).
  • Select the target I want to add the library to.
  • Select the Build phases tab.
  • Expand Link binary with Libraries.
  • Click the [+] button to add a framework.
  • Click the [Add Other ...] button and navigate to the directory containing the <lib>.framework directory and select that.

Thats all. The targets search paths will be updated to include the framework directory and the framework will be listed on the left under the project. Expanding it will show the headers.

The problem you mention sound like a couple of things. Firstly the framework not found sounds like the framework has not been included in the target. When you select the framework in the project list on the left, you should be able to see it's Target Membership displayed on the right. Check it's on for the target you are compiling.

Secondly building frameworks is not a trivial task so don't attempt it unless you have the scripts to do it. I say this because building a iOS static framework means compiling for both simulator and devices, combining the compiled lib files into a universal one, and then storing it and the header in a specific directory strucuture.

The downloaded zip from OCHamcrest though, appears to have the correct OCHamcrestiOS.framework in it. So if you store that directory somewhere and link to it using the steps I've outlined above it should work just fine.