Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang compiling error (undefined reference to objc_autoreleasepoolpush)

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?

like image 404
Nils Avatar asked Feb 17 '13 13:02

Nils


3 Answers

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.

like image 136
WeakPointer Avatar answered Sep 20 '22 14:09

WeakPointer


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.

like image 36
Martin R Avatar answered Sep 19 '22 14:09

Martin R


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.

like image 22
Fred Frith-MacDonald Avatar answered Sep 18 '22 14:09

Fred Frith-MacDonald