Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Hello World in Objective-C with clang and gnustep does not compile

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.

like image 751
SwiftMango Avatar asked Nov 19 '12 01:11

SwiftMango


People also ask

Does Clang compile Objective-C?

These days, Xcode ships with clang as the compiler. Wherever we write compiler, you can read it as clang. clang is the tool that takes Objective-C code, analyzes it, and transforms it into a more low-level representation that resembles assembly code: LLVM Intermediate Representation.

How to run Objective-c on windows?

In order to run Objective-C program on windows, we need to install MinGW and GNUStep Core. Both are available at https://www.gnu.org/software/gnustep/windows/installer.html. First, we need to install the MSYS/MinGW System package. Then, we need to install the GNUstep Core package.

Can you program Objective-c on windows?

The best platform for developing Objective‑C is Mac OS. But Objective‑C programs can also be compiled and run on Windows or Linux by using GNUstep and an Objective‑C compiler.


1 Answers

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
like image 186
Tomas Camin Avatar answered Oct 02 '22 10:10

Tomas Camin