So, I got Ubuntu and clang3.0 installed and a simple program.m:
#include <Foundation/Foundation.h>
int main()
{
@autoreleasepool{
NSLog(@"Hi");
}
return 0;
}
and I try to compile it like this:
clang first.m -I /usr/include/GNUstep/ -lgnustep-base -fconstant-string-class=NSConstantString -objc
and I get
undefined reference to objc_autoreleasePoolPush
undefined reference to objc_autoreleasePoolPop
so I've googled a little and install objc2 and tried:
clang first.m -I /usr/include/GNUstep/ -lgnustep-base -fconstant-string-class=NSConstantString -objc2
but nothing changes. Maybe someone had same problem solved?
With libobjc2 installed on my Ubuntu system, a copy of your first.m files compiles for me with this line:
clang first.m `gnustep-config --objc-flags` `gnustep-config --objc-libs` \
-I /usr/include/GNUstep/ -lgnustep-base
but maybe it is simply a typo at the end of your command lines?
The -objc at the end of your first example and the -objc2 at the end of the second are instructing the clang compiler to create executables with names bjc and bjc2, respectively. Did you mean -lobj? I think linking in the obj library is critical for getting an Objective-C runtime library. Even with the libobjc2 project, the library produced is still named libobjc.so.x.y. If your command doesn't include a -lobjc, I don't see how it could ever link correctly. I could be wrong but it doesn't work for me without it.
I am not sure if this applies to GNUstep, but on OS X you have to add the -fobjc-arc
compiler flag if you want to compile with ARC.
Try to build it with GNUmakefile?
Here's how to write one.
http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/node2.html
One could be compiled and linked like
clang first.m -c -MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fobjc-runtime=gnustep-1.7 -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -fobjc-nonfragile-abi -D_NONFRAGILE_ABI -pthread -fPIC -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -fgnu-runtime -fconstant-string-class=NSConstantString -I. -I/usr/local/include -o obj/first.obj/first.m.o
clang -rdynamic -pthread -shared-libgcc -fexceptions -fobjc-nonfragile-abi -fgnu-runtime -o obj/first ./obj/first.obj/first.m.o -L/usr/local/lib -lgnustep-base -lobjc -lm
Depending on how you configure the GNUstep make package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With