7

System:

64bit Ubuntu Lucid
GNUStep
clang/LLVM

test.m

#import <Foundation/Foundation.h>

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

compile command line:

clang -fobjc-gc -I /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include -I /usr/include/GNUstep/ -I /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include-fixed/ -L /usr/lib/GNUstep/ -L /usr/lib64/ -fconstant-string-class=NSConstantString -rpath /usr/lib64 -Xlinker -lgnustep-base  test.m -o Test

error:

/usr/bin/ld: /usr/lib64//libgnustep-base.so: undefined reference to symbol '__objc_exec_class'
/usr/bin/ld: note: '__objc_exec_class' is defined in DSO /usr/lib64/libobjc.so.2 so try adding it to the linker command line
/usr/lib64/libobjc.so.2: could not read symbols: Invalid operation
clang: error: linker command failed with exit code 1 (use -v to see invocation)

While using GCC, it compiles fine, but clang does not.

SwiftMango
  • 15,092
  • 13
  • 71
  • 136

1 Answers1

12

On a fresh install of Ubuntu 12.10 I installed the following packages:

$ sudo apt-get install build-essential
$ sudo apt-get install clang
$ sudo apt-get install gnustep
$ sudo apt-get install gnustep-make
$ sudo apt-get install gnustep-devel
$ sudo ln -s /usr/lib/gcc/i686-linux-gnu/4.7/include/objc /usr/local/include/objc

(the final symlink is required to properly locate the objc.h header)

Then I compiled the test.m file as follows:

$ clang -o test test.m -I `gnustep-config --variable=GNUSTEP_SYSTEM_HEADERS` \
                       -L `gnustep-config --variable=GNUSTEP_SYSTEM_LIBRARIES` \
                       -lgnustep-base -fconstant-string-class=NSConstantString \
                       -D_NATIVE_OBJC_EXCEPTIONS \
                       -lobjc

tux@ubuntu:~/Desktop$ ./test 
2012-11-20 11:02:08.184 test[11856] Hello world!

* EDIT

On a fresh 10.04-64bit this allows to compile just fine:

$ sudo apt-get install build-essential
$ sudo apt-get install clang
$ sudo apt-get install gnustep-devel
$ sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include/objc/ /usr/local/include/objc
Tomas Camin
  • 9,996
  • 2
  • 43
  • 62
  • 1
    -______________- it now gives me an error saying `/usr/bin/ld: cannot find -lobjc`. I installed all the listed items already... – SwiftMango Nov 21 '12 at 04:55
  • 1
    `/usr/bin/ld: /tmp/test-2JGYua.o: undefined reference to symbol '__objc_exec_class' /usr/bin/ld: note: '__objc_exec_class' is defined in DSO /usr/lib64/libobjc.so.2 so try adding it to the linker command line /usr/lib64/libobjc.so.2: could not read symbols: Invalid operation clang: error: linker command failed with exit code 1 (use -v to see invocation)` – SwiftMango Nov 22 '12 at 01:41
  • See the updated answer, I've added the -lobjc to the clang flags – Tomas Camin Nov 22 '12 at 09:36
  • Yeah man it tells me again cannot find lobjc... I gave up, and thanks for help, at leadt tried :) – SwiftMango Nov 23 '12 at 02:03
  • 3
    I wrote [a Gist](https://gist.github.com/nicerobot/5652802) to automate it. It worked for me in Ubuntu 12.10. – nicerobot May 26 '13 at 16:39