Search code examples
objective-cxcodelinker-errorsquicklook

Renaming Quicklook-template GeneratePreviewForURL.m causes linker error


I'm using a slightly outdated version of Xcode (4.2.1, with Apple clang version 3.0), which might be a problem, but.. this should work regardless:

I create a new Quicklook plugin project ("File > New > New Project", then "System Plugin > Quick Look Plug-in")

Then I rename GeneratePreviewForURL.c to GeneratePreviewForURL.m (as mentioned in the Apple docs)

If I try and use any Objective-C code in the file, I get errors. For example if I add the following to the GeneratePreviewForURL method:

#include <Foundation/Foundation.h> // at start of file

NSMutableDictionary *blah;
[blah setValue:@"valuething" forKey:@"keything"];

I get the following linker error:

Undefined symbols for architecture x86_64:
  "_objc_msgSend", referenced from:
      _GeneratePreviewForURL in GeneratePreviewForURL.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The slightly trimmed/reformmated linker command causing the problem is:

cd ~/QuicklookExample

setenv MACOSX_DEPLOYMENT_TARGET 10.7

/Developer/usr/bin/clang
-arch x86_64 -bundle
-isysroot /Developer/SDKs/MacOSX10.7.sdk
-L/snip -F/snip -filelist /snip/QuicklookExample.LinkFileList
-mmacosx-version-min=10.7
-framework QuickLook
-framework ApplicationServices
-framework CoreServices
-framework CoreFoundation
-o /snip/QuicklookExample

Solution

  • You have to add at least Foundation framework to the linked libraries.

    Note that what's missing here is libobjc which should be linked directly by the fact clang should understand your code is actually Objective-C.