7

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?

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
Manifestor
  • 575
  • 5
  • 19

3 Answers3

2

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.

WeakPointer
  • 3,087
  • 27
  • 22
  • thanks WeakPointer ) clang first.m `gnustep-config --objc-flags` `gnustep-config --objc-libs` -I /usr/include/GNUstep/ -lgnustep-base -I /home/nazar/libobjc2/ this works fine but I get warning: argument unused during compilation: '-shared-libgcc' thanks again ) – Manifestor Mar 12 '13 at 05:09
  • and now I get warning: libobjc.so.3, needed by /usr/lib/libgnustep-base.so, may conflict with libobjc.so.4 – Manifestor Aug 03 '13 at 22:24
1

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.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • 1
    According to http://wiki.gnustep.org/index.php/ObjC2_FAQ, you have to add the `-fobjc-nonfragile-abi` option. – Martin R Feb 17 '13 at 21:08
1

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.

  • Huh? What has the makefile got to do with the OP's linker issue? – trojanfoe Feb 19 '13 at 16:55
  • It is not just a makefile, it's a makefile that include configured options. GNUstep make package usually provide the options that was used to build the GNUstep libraries, includingn linker options. – Fred Frith-MacDonald Feb 19 '13 at 23:19