views:

637

answers:

3

Hello,

I learning Objective-C in Linux(Ubuntu), but when i tryed to compile my application that needs the Foundation headers i got an error saying that the file cannot be found, but i have installed the GNUstep development package(gnustep-devel). Here is my code:

// Fraction.h
#import <Foundation/NSObject.h>

@interface Fraction: NSObject {
    int numerator;
    int denominator;
}

- (void) print;
- (void) setNumerator: (int) n;
- (void) setDenominator: (int) d;
- (void) numerator;
- (void) denominator;
@end

And here is the console log:

ubuntu@eeepc:~$ gcc main.m -o frac -lobjc
In file included from main.m:3:
Fraction.h:2:26: error: objc/NSObject.h: No such file or directory
In file included from main.m:3:
Fraction.h:4: error: cannot find interface declaration for ‘NSObject’, superclass of ‘Fraction’
ubuntu@eeepc:~$

What i need to do?

+1  A: 

how are you compiling it? For me, I create a GNUMakefile makefile for my application (see here), and then I run source /usr/share/GNUstep/Makefiles/GNUstep.sh and then make.

newacct
A: 

I've searched at the repository and then i installed the foundation lib, now all is working.

Thanks.

Nathan Campos
+3  A: 

GNUstep Installation Process For Windows

  1. Visit The URL: http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/
  2. Download the exe file gnustep-system-0.19.2-setup.exe
  3. Then Download gnustep-core-0.19.2-setup.exe

Remember one thing if you are downloading gnustep-system of any version you must have to download the same version for gnustep-core. For example if you have downloaded gnustep-setup-0.22.1-setup.exe then you must have to download gustep-core-0.22.1-setup.exe otherwise your code will not run.

  1. Install first the gnustep-system-0.19.2-setup.exe then install gnustep-core-0.19.2setup.exe. Don’t try to install in vice versa order.
  2. Now you got the gnustep for windows then go to start>all program> GNUstep> shell
  3. Now open the notepad editor and write the following code in notepad
#import  
int main (int argc, const char * argv[])
{
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]  
init];
  NSLog (@"Anil Kumar Yadav has Run the First Objective C  
program!");
  [pool drain];
  return 0;
}

save it as hello.m in your C:/GNUstep/home/foldername Remember foldername is the name when you first time start the shell it create the envoirment and make a folder by the name of your computer name in C:/GNUstep/home folder. So don’t be panic.Okay

  1. Go to your shell and type the following command gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -constant-string-class=NSConstantString
  2. This command will create a hello.exe file in your foldername folder.
  3. Again in shell type the command ./hello.exe

Finally you will be able to see the output in the shell.

Conguratulation you wrote your first Objective C program successfully. Need any clarification write me to : [email protected]

Anil Kumar Yadav