How to Compile Objective-C 2.0 code in FreeBSD using clang?

Hi!

I have the following files:

example.m
Code:
#import <Foundation/Foundation.h>

int main( int argc, const char *argv[] ) {

    NSLog (@"First ObjC Program");

    return 0;
}

GNUmakefile
Code:
GNUSTEP_MAKEFILES=/usr/local/GNUstep/System/Library/Makefiles

include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = exampleapp
exampleapp_OBJC_FILES = example.m

include $(GNUSTEP_MAKEFILES)/tool.make

I have libobjc2 and gnustep installed and when I run:
Code:
clang -ObjC example.m -o example \
-I/usr/local/lib  \
-I/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.1/4.2.5/include \
-fconstant-string-class=NSConstantString -I/usr/local/GNUstep/System/Library/Headers \
-L/usr/local/GNUstep/System/Library/Libraries \
-L/usr/local/lib -lgnustep-base

./example

I get the following error:
Code:
Module ./example.m version 9 doesn't match runtime 8
Abort (core dumped)

That's not good! When I run:
Code:
clang `gnustep-config --objc-flags` example.m -o example  `gnustep-config --base-libs` -I/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.1/4.2.5/include -I/usr/local/GNUstep -L/usr/local/GNUstep -I/usr/local/GNUstep/System/Library/Headers -L/usr/local/GNUstep/System/Library/Libraries -L/usr/local/lib

I get the following compilation error:
Code:
gnustep-config: Command not found.
gnustep-config: Command not found.
/usr/lib/crt1.o: In function `_start':
/usr/src/lib/csu/amd64/crt1.c:(.text+0x82): undefined reference to `main'
/tmp/example-O1DIn2.o: In function `gnustep_base_user_main':
example.m:(.text+0x1d): undefined reference to `NSLog'
/tmp/example-O1DIn2.o: In function `.objc_load_function':
example.m:(.text+0x3f): undefined reference to `__objc_exec_class'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

That's really not good! Finally if I try:
Code:
gmake CC=clang CXX=clang++

I get the following compilation error:
Code:
This is gnustep-make 2.6.2. Type 'gmake print-gnustep-make-help' for help.
/usr/local/GNUstep/System/Library/Makefiles/common.make:857: WARNING: Your PATH may not be set up correctly !
/usr/local/GNUstep/System/Library/Makefiles/common.make:858: Please try again after adding "/usr/local/GNUstep/System/Tools" to your path
Making all for tool exampleapp...
 Compiling file example.m ...
In file included from example.m:1:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/Foundation.h:33:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/FoundationErrors.h:29:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObject.h:30:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObjCRuntime.h:95:
In file included from /usr/local/GNUstep/System/Library/Headers/GNUstepBase/GSObjCRuntime.h:85:
/usr/local/GNUstep/System/Library/Headers/ObjectiveC2/objc/runtime.h:42:27: warning: 
      redefinition of typedef 'Ivar' is a C11 feature [-Wtypedef-redefinition]
typedef struct objc_ivar* Ivar;
                          ^
/usr/local/include/objc/runtime.h:52:27: note: previous definition is here
typedef struct objc_ivar* Ivar;
                          ^
In file included from example.m:1:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/Foundation.h:33:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/FoundationErrors.h:29:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObject.h:30:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObjCRuntime.h:95:
In file included from /usr/local/GNUstep/System/Library/Headers/GNUstepBase/GSObjCRuntime.h:85:
/usr/local/GNUstep/System/Library/Headers/ObjectiveC2/objc/runtime.h:83:15: error: 
      typedef redefinition with different types ('void *' vs 'struct objc_property *')
typedef void *objc_property_t;
              ^
/usr/local/include/objc/runtime.h:139:31: note: previous definition is here
typedef struct objc_property* objc_property_t;
                              ^
In file included from example.m:1:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/Foundation.h:33:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/FoundationErrors.h:29:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObject.h:30:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObjCRuntime.h:95:
In file included from /usr/local/GNUstep/System/Library/Headers/GNUstepBase/GSObjCRuntime.h:85:
/usr/local/GNUstep/System/Library/Headers/ObjectiveC2/objc/runtime.h:127:1: error: 
      unknown type name 'Method_t'; did you mean 'Method'?
Method * class_copyMethodList(Class cls, unsigned int *outCount);
^~~~~~
Method
/usr/local/GNUstep/System/Library/Headers/ObjectiveC2/objc/runtime.h:78:17: note: 
      expanded from macro 'Method'
#       define Method Method_t
                      ^
/usr/local/include/objc/runtime.h:115:29: note: 'Method' declared here
typedef struct objc_method *Method;
                            ^
In file included from example.m:1:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/Foundation.h:33:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/FoundationErrors.h:29:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObject.h:30:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObjCRuntime.h:95:
In file included from /usr/local/GNUstep/System/Library/Headers/GNUstepBase/GSObjCRuntime.h:85:
/usr/local/GNUstep/System/Library/Headers/ObjectiveC2/objc/runtime.h:136:1: error: 
      unknown type name 'Method_t'; did you mean 'Method'?
Method class_getClassMethod(Class aClass, SEL aSelector);
^~~~~~
Method
/usr/local/GNUstep/System/Library/Headers/ObjectiveC2/objc/runtime.h:78:17: note: 
      expanded from macro 'Method'
#       define Method Method_t
                      ^
/usr/local/include/objc/runtime.h:115:29: note: 'Method' declared here
typedef struct objc_method *Method;

/usr/local/include/objc/runtime.h:115:29: note: 'Method' declared here
typedef struct objc_method *Method;
                            ^
1 warning and 17 errors generated.
gmake[3]: *** [obj/exampleapp.obj/example.m.o] Error 1
gmake[2]: *** [internal-tool-all_] Error 2
gmake[1]: *** [exampleapp.all.tool.variables] Error 2
gmake: *** [internal-all] Error 2

Question: does anyone know how to compile a simple Objective-C framework using libobjc2?

Thanks!

(I am using FreeBSD 9.1 AMD64 and gnu step/libobjc2/libdispatch have been successfully installed)
 
Here are my steps to reproduce this problem

I have attached a shell script file which basically sets you up and running for gnustep/libobjc2. Did I do anything wrong?

Code:
#!/bin/sh

portsnap fetch
portsnap extract
portsnap update

#------------#
# CLANG/LLVM #
#------------#
cd /usr/ports/devel/llvm-devl/
make install -DBATCH clean
echo 'WITH_CLANG_EXTRAS=YES' >> /etc/src.conf
echo 'CC=clang' >> /etc/make.conf
echo 'CXX=clang++' >> /etc/make.conf
echo 'CPP=clang-cpp' >> /etc/make.conf

#------------------------#
# Compile Kernel / World #
#------------------------#
# Note: The next steps will only work if
# there are source data in the folder....
cd /usr/src

# Build the world using CLANG/LLVM
make buildworld

# Built kernel:
make buildkernel

# Installed kernel:
make installkernel
mergemaster -p

# Install world:
make installworld
mergemaster -p

reboot

# Install subversion
cd /usr/ports/devel/subversion
make install -DBATCH clean
rehash

# install dependencies for GNUstep and then delete it
cd /usr/ports/devel/gnustep
make install clean

# Make sure to install libdispatch as well!
cd /usr/ports/lang/libobjc2
make install clean

# Setup GNUstep with FreeBSD
cd /usr/local/GNUstep/System/Library/Makefiles
chmod u+x GNUstep.csh
./GNUstep.csh

# SH
echo 'GNUSTEP_SYSTEM_TOOLS=/usr/local/GNUstep/System/Tools' >> ~/.profile
echo 'export GNUSTEP_SYSTEM_TOOLS' >> ~/.profile

# CSCH
echo 'setenv  GNUSTEP_SYSTEM_TOOLS    /usr/local/GNUstep/System/Tools' >> ~/.cshrc

# Make.conf
echo 'GNUSTEP_WITH_CLANG=yes' >> /etc/make.conf
echo 'WITH_GNUSTEP_DEVEL=yes' >> /etc/make.conf
echo 'GNUSTEP_WITH_LIBOBJC2=yes' >> /etc/make.conf
 
Back
Top