objc_exec_class on Mac OS X

Hi,

I've been trying to get clang to compile Objective-C code on Mac OS X for a while now. I keep getting linker errors of the form

Undefined symbols:
   "___objc_exec_class", referenced from:
       _.objc_load_function in cc5ZSPXw.o

and from what I can tell, _objc_exec_class is a GNUStep function which is apparently not in Apple's libobjc. In case anyone wants to try this themselves, compiling the following with "clang -emit-llvm-bc -x=objective-c < hello.m | llc > hello.s" and then "gcc -o hello -framework Foundation -lobjc hello.s" fails with the undefined symbol message above.

#import <Foundation/Foundation.h>

int main(int argc, char const *argv) {
  NSLog(@"Hello, world!");
  // printf("Hello, world!\n");
  
  return 0;
}

Any ideas?

Brendan Younger

Does it work if you use the -fnext-runtime flag?

On Mac OS X, this should be the default, however it appears that you are getting code for the GNU runtime. I just scanned over the implementation and don’t see an obvious problem. What is your target triple?

  • Daniel

“llvm-config --host-triple” gives:

i686-apple-darwin9.5.0

and “clang -emit-llvm-bc -fnext-runtime hello.m” gives
clang: Unknown command line argument ‘-fnext-runtime’. Try: ‘clang --help’

This is all from the current svn.

Brendan Younger

Are you sure the clang you are using is from svn? If that option is
present you must be working with a much older clang.

Make sure that you are actually running the version you expect (i.e.
that 'which clang' shows the appropriate build of clang, if you are
building a debug build this should be something like
'.../llvm/Debug/bin/clang'.

- Daniel

Thanks, apparently I wasn't building clang at the same time as LLVM. Fixed it by adding clang to the tools/Makefile

Brendan