New |
New |
Home |
---|
[Updated on 8th May 2012]
Hi,
as I'm about to become an iPhone programmer (another one?), I've decided to set up an objective-c environment on my Ubuntu too.
First, I've installed the following packages:
sudo apt-get install gnustep-devel gnustep-make libgnustep-base-dev
Second, I've tried to compile a classical Hello World file with gcc. Here's the code ('Ciao mondo' stands for 'Hello world' in Italian):
#import <Foundation/Foundation.h> int main(int argc, char* argv[]) { NSLog(@"Ciao mondo"); return 0; }
and i saved the source in a file called main.m
After that I've tried: gcc main.c -o hello and I soon got the following error message:
main.m:2:34: error: Foundation/Foundation.h: No such file or directory main.m: In function ‘main’: main.m:5: error: cannot find interface declaration for ‘NXConstantString’
So after surfing a while on Yahoo's search results, I came to the solution:
1. Execute
. /usr/share/GNUstep/Makefiles/GNUstep.sh
to initialize the environment variables for the GNUstep.
2. Use the gnustep-config --objc-flags to retrieve the correct flags for gcc and link the main.m with the gnustep-base library, this way:
clang `gnustep-config --objc-flags` -v main.m -lgnustep-base -o hello
3. Execute ./hello and you'll got:
2012-05-08 11:25:30.308 a.out[14082] Ciao mondo
If you prefere, you can use CLang too the same way:
clang `gnustep-config --objc-flags` -v main.m -lgnustep-base -o hello
Enjoy,
Rob.