I am attempting to compile a simple application that references GNUstep classes, with GNUstep on my Ubuntu 14.04, 64 bit, machine:
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
int main(int argc, char **argv)
{
NSString *bestType = [[NSPasteboard generalPasteboard]
availableTypeFromArray: nil];
NSLog(@"best type: %@", bestType);
return 0;
}
Here are my compile and link flags (some of which may be overkill):
CFLAGS=`gnustep-config --objc-flags` -std=gnu99
LDFLAGS=`gnustep-config --base-libs` -lgnustep-base -lobjc -lm -lglut -lGLU -lGL
Before compilation I ran the script:
/usr/share/GNUstep/Makefiles/GNUstep.sh
And here is the output from 'make -n'
gcc main.m `gnustep-config --objc-flags` -std=gnu99 -L. `gnustep-config --base-libs` -lgnustep-base -lobjc -lm -lglut -lGLU -lGL -o tester
But when linking, Cocoa classes seem to not be pulled in, and I get an undefined reference error:
/tmp/ccnyXBoH.o:(.data.rel+0x8): undefined reference to `__objc_class_name_NSPasteboard'
If I remove all references to Cocoa classes in main.m, the app compiles without error.
The reason why you can't find the class definition for NSPasteboard
is because it's in the gnustep-config --gui-libs
options - i.e. the symbol is in the gui library of GNUStep
, not in the base library of GNUStep
. The solution is to change the LDFLAGS
line to:
LDFLAGS=`gnustep-config --gui-libs` -lglut -lGLU -lGL
You shouldn't need to double-specify -lgnustep-base -lobjc -lm
- they're part of both --base-libs
and --gui-libs
.