title: How to add CocoaHTTPServer to an iOS project on XCode 4
body: <p>I'm trying to add <a href="https://github.com/robbiehanson/CocoaHTTPServer" rel="nofollow noreferrer">CocoaHTTPServer</a> to my project. I encountered many problems on the way - my problem (adding CocoaHTTPServer to a project (and have it working)) is still there - but I've also included the errors and solutions I encountered on the way for others' reference.</p>
  
  <p>First I looked at tutorials on adding a framework, but it didn't look like a framework.</p>
  
  <p>Next I right clicked on my project (on the left sidebar), and manually added it with "add files". I followed the <a href="https://github.com/robbiehanson/CocoaHTTPServer/blob/master/Samples/SimpleHTTPServer/AppDelegate.m" rel="nofollow noreferrer">SimpleHTTPServer</a> example but got a "cocoa/cocoa.h" not found error. I searched around and found that Cocoa is for mac and not iOS. But the CocoaHTTPServer description talks about iOS apps too, so I just deleted the samples folder (the error was coming from the <a href="https://github.com/robbiehanson/CocoaHTTPServer/tree/master/Samples/DynamicServer" rel="nofollow noreferrer">DynamicHTTPServer</a> example if I recall.</p>
  
  <p>Then I got a "Lexical or preprocessor issue libxml/parser.h not found" error. I tried adding it as a framework, but that didn't work. I found this tutorial on <a href="http://www.cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html" rel="nofollow noreferrer">adding libxml to the header search path</a> (at the end), but I ended up with 46 "Apple Mach-O Linker Error _CFHTTPMessage..." errors, and I decided to ask my question here. I tried <a href="https://stackoverflow.com/a/10904246/1092951">this answer</a> but got many Apple Mach-O Linker Errors</p>
  
  <p>I added CFNetwork and Security frameworks (project => build phases => link binary with libraries), and was left with 2 errors:</p>
  
  <pre><code>ld: warning: path '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/usr/lib/libxml2.dylib' following -F not a directory
  Undefined symbols for architecture i386:
    "_NSlog", referenced from:
        -[AppDelegate application:didFinishLaunchingWithOptions:] in AppDelegate.o
  ld: symbol(s) not found for architecture i386
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>I see i386 which is intel, and not the ARM architecture on iDevices. However, the real problem was I mispelled <code>NSLog</code> (look carefully - it wasn't capitalized in the error message). When I googled this - other possible causes may be missing frameworks.</p>
  
  <p>Now it compiles. When I run the sample application, I get the "server started on X port" and when I go to <code>localhost:X</code> I get the welcome/success screen. When I do the same on my project, I still get the "server started on X port" messages, but when I go to <code>localhost:X</code> the browser gives a "cannot connect" messages. No errors in the XCode console.</p>
  
  <p>There are no errors from <code>[httpServer start:&amp;error]</code> and <code>httpServer.isRunning</code> is true.</p>
  
  <hr>
  
  <p>So what's the best way to add CocoaHTTPServer to my project? In terms of a clean setup - for example, when I inspect the sample <a href="https://github.com/robbiehanson/CocoaHTTPServer/tree/master/Samples/iPhoneHTTPServer" rel="nofollow noreferrer">iPhone project</a>, I don't see any of the messy steps to add libxml - I don't even see libxml anywhere at all. And in terms of configuring everything so that it actually works and serves files. Right now, I'm suspecting there may be some project settings that need to be enabled for it to actually be a server.</p>