How can I include non-framework libraries when writing CodeRunner documents?

2k views Asked by At

I've been using CodeRunner to collect little chunks of code that are frequently used while developing but don't necessarily belong in the codebase for a project. It's a great tool for summarizing in Objective-C and Cocoa because I can include frameworks that are installed on my machine.

However, sometimes I want to include functionality from external sources that aren't frameworks, such as ASIHTTPRequest. If I place the ASIHTTPRequest files in a folder nearby and #include them, I get errors about "Undefined symbols for architecture x86_64: _OBJC_CLASS_$_ASIHTTPRequest" which I'm assuming means that the ASI files simply aren't being compiled and linked with the CodeRunner doc - this is a single file being compiled, not a project. In Xcode I would add the ASIHTTPRequest files to the project and they would automatically be compiled and linked with the rest of the code, what is the equivalent when I'm not using Xcode?

I can include custom arguments and compilation flags (the latter contains -std=c99 -framework Foundation by default) and I suspect I have to tweak these somehow but I haven't been able to find out how.

1

There are 1 answers

2
Brad Choate On BEST ANSWER

I got it to work. gcc requires some additional parameters to link to the ASIHTTP modules, of course. Here's what I ended up with:

-std=c99 -framework SystemConfiguration -framework CoreServices -framework Foundation -lz -I/path/to/asi-header-files -filelist /path/to/list-of-asi-compiled-modules

I imagine your code was just including paths to the ASIHTTPRequest.h, etc. header files... if you're using explicit paths there, you don't need the -I switch above. gcc does need to have a compiled version of the code from ASIHTTPRequest.m and friends to link with it. One way to do that is to compile the "Mac" project that comes with the library. That will produce .o files in one of those deeply-buried "DerivedData" directories Xcode likes to make. The one it made for me is:

~/Library/Developer/Xcode/DerivedData/Mac-flsjygxmngizhzfwnfgcakejmwkx/Build/Intermediates/Mac.build/Debug/Mac.build/Objects-normal/x86_64

(The "Mac-flsjygxmngizhzfwnfgcakejmwkx" bit will differ for you, I imagine.) In that directory, there are a bunch of .o files and a 'Mac.LinkFileList' file. This file is the one you'd give for the -filelist parameter to gcc. You'll need to remove references to the main.o, AppDelegate.o and ASIWebPageRequest.o files so you don't get duplicate symbol errors during the link step.

In addition to the ASIHTTPRequest header and .o files, gcc will expect to link with the SystemConfiguration, CoreServices frameworks and the zlib library, since ASIHTTPRequest has those dependencies.

If you're doing lots of tests with this library, I would recommend duplicating the "Objective-C" language definition (under Preferences) as "Objective-C with ASIHTTPRequest" or something. Then you can customize the compilation flags for running against ASIHTTPRequest without making it do that for all Objective-C code you run.

You may also want to copy the .o files and the "LinkFileList" file to a more permanent place, just in case Xcode cleans that build tree away or something.