3

I'm trying to add CocoaHTTPServer 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.

First I looked at tutorials on adding a framework, but it didn't look like a framework.

Next I right clicked on my project (on the left sidebar), and manually added it with "add files". I followed the SimpleHTTPServer 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 DynamicHTTPServer example if I recall.

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 adding libxml to the header search path (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 this answer but got many Apple Mach-O Linker Errors

I added CFNetwork and Security frameworks (project => build phases => link binary with libraries), and was left with 2 errors:

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)

I see i386 which is intel, and not the ARM architecture on iDevices. However, the real problem was I mispelled NSLog (look carefully - it wasn't capitalized in the error message). When I googled this - other possible causes may be missing frameworks.

Now it compiles. When I run the sample application, I get the "server started on X port" and when I go to localhost:X 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 localhost:X the browser gives a "cannot connect" messages. No errors in the XCode console.

There are no errors from [httpServer start:&error] and httpServer.isRunning is true.


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 iPhone project, 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.

Community
  • 1
  • 1
Raekye
  • 5,081
  • 8
  • 49
  • 74

1 Answers1

2

While adding the external files, have you checked your project as a "Build Target"?

A common Mistake

Siddharth Gupta
  • 897
  • 5
  • 20
  • Also, have you added the CFNetwork Framework to your project? – Siddharth Gupta Jun 14 '13 at 16:09
  • Actually yes, that's what I started doing (imported the sample project, and compared build settings). Getting many fewer errors now (also imported Security), I'll let you know after I reach my next block – Raekye Jun 14 '13 at 16:10
  • Updated question with my current progress. Do you know instructions to set it up from start (cloning git repo) to finish? Edit: Holy crap the last error was just a mispelling of NSLog/NSlog. But since it looked like the other Apple-Mach-O errors I assumed it was something to do with the CocoaHTTPServer. I'll update once I confirm a few other things – Raekye Jun 14 '13 at 17:06
  • Now, I get the "server started on port X" messages, but when I go to `localhost:X` I get a cannot connect message. When I start the server on the example application, I get the same "server started" messages and it does connect – Raekye Jun 16 '13 at 19:40
  • Well, I answered this question, because I knew how to solve the linker error. I have no experience with CocoaHTTPServer. Sorry. – Siddharth Gupta Jun 16 '13 at 19:43
  • You brushed on what ended up being part of the solution to get it compiling, so I gave you a +1. However, I don't considered the question `how to add cocoahttpserver to a project` complete because it compiles but not everything is done right (it isn't working). I'll see if anyone else can figure something out. Thanks for your time though – Raekye Jun 16 '13 at 19:53