views:

6010

answers:

11

I just installed GNUstep on my Windows XP machine and I'm attempting to compile the following Objective-C Hello World program from the command line:

#import <Foundation/Foundation.h>

int main(int argc, const char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSLog(@"Hello world\n");

    [pool drain];
    return 0;
}

When I try to compile the program from the command line like so

gcc hello.m -o hello

I end up getting the following error

hello.m:1:34: Foundation/Foundation.h: No such file or directory

Is there something I need to do order to inform the compiler of where the standard Objective-C libraries are located?

+6  A: 

Have a look here. It seems like one needs a bunch of parameters to the compile command.

epatel
The link provided here has good information on how to setup GNUstep on Windows and compile a simple Objective-C program. The key thing I was doing incorrectly was attempting to execute gcc and make from the DOS prompt instead of from within the MING shell as required (All Programs->GNUstep->Shell).
Jason Roberts
I got this error:error : cannot find interface declaration for 'NXConstantString'.and got it solved after adding this to compiler:-fconstant-string-class=NSConstantString
yehnan
A: 

I tried typing in

gcc hello.m -o hello -framework Foundation

however I get the following error:

gcc: Foundation: No such file or directory and
cc1obj.exe: error: unrecognized command line option "-framework"

I also tried typing in

gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base

but I get the same error.

Yup, I wrote that before. My mistake, I was thinking MacOSX...sorry
epatel
+1  A: 

You need to tell the compiler where the GNUstep headers and frameworks are located. The easiest way (at least on Unix systems, I'll be honest and say that I've not used GNUstep on Windows) is to use gnustep-make. You could have a GNUstep-make file as simple as

include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = hello
hello_OBJC_FILES = hello.m

include $(GNUSTEP_MAKEFILES)/tool.make
Graham Lee
I finally realized that you're supposed to execute the gcc and make commands from within the MING shell found under All Programs->GNUstep->Shell, and not at the DOS prompt as I was attempting to do.
Jason Roberts
A: 

epatel. did you ever get that to work?

A: 

Hi,I am getting the same error when I compile using gnustep mingw32 on win XP.

I am trying a simple program:

#

ClassTest.h


import

import

@interface ClassTest: NSObject

{

int a; int b; }

-(void) setvara : (int) x; -(void) setvarb : (int) y; -(int) add;

@end

ClassTest.m


import

import"ClassTest.h"

@implementation ClassTest

{ -(void) setvara :(int) x { a=x; }

-(void) servarb: (int) y
{
 b=y;
}

-(int) add
{
 return a+b;
}

}

@end

ClassTestMain.m


import

import"ClassTest.m"

imt main() {

ClassTest *class = [[ClassTest alloc]init];
[class setvara : 5];
[class servarb : 6];
printf("Sum is:%d", [class add]);
[class release];
return;

}

#

$ gcc -o test ClassTest.h ClassTest.m ClassTestMain.m

ClassTest.h:2:32: Foundation/NSobject.h: No such file or directory ClassTest.h:5: error: stray '@' in program ClassTest.h:5: error: syntax error before "ClassTest" ClassTest.h:11: error: syntax error before '}' token ClassTest.h:17: error: stray '@' in program ClassTest.h:17:5: warning: no newline at end of file In file included from ClassTest.m:2: ClassTest.h:2:32: Foundation/NSobject.h: No such file or directory In file included from ClassTest.m:2: ClassTest.h:11: error: cannot find interface declaration for NSObject', supercl ass of ClassTest' In file included from ClassTest.m:2, from ClassTestMain.m:2: ClassTest.h:2:32: Foundation/NSobject.h: No such file or directory In file included from ClassTest.m:2, from ClassTestMain.m:2: ClassTest.h:11: error: cannot find interface declaration for NSObject', supercl ass of ClassTest'

#
+2  A: 

I just made a file called "GNUmakefile" and plonked this into it:

include ${GNUSTEP_MAKEFILES}/common.make

TOOL_NAME = MyApp
MyApp_OBJC_FILES = code.m

include ${GNUSTEP_MAKEFILES}/tool.make

then I proceeded to just type 'make' at the prompt. The output is written out to obj\MyApp.exe

That did it for me. screw stuffing about with gcc command line.

I tried it but get errors:$ make -f Test1.makeThis is gnustep-make 2.2.0. Type 'make print-gnustep-make-help' for help.Making all for tool Test1...make[1]: GNUmakefile: No such file or directorymake[1]: *** No rule to make target `GNUmakefile'. Stop.make: *** [Test1.all.tool.variables] Error 2
Sunit
To use a different filename than GNUmakefile you must provide both the -f and MAKEFILE_NAME arguments. >> make -f Prog1Makefile MAKEFILE_NAME=Prog1Makefile
Wade
+1  A: 

My GNUstep installation is in c:\GNUstep\GNUstep\System. If yours is different, you should change the import of Foundation.h accordingly.

I did this:

  1. Create c:\myprogs\obj-c\hello\hello.m that looks like this:

//---------- Hello.m

#import <../../GNUstep/System/Library/Headers/Foundation/Foundation.h>

int main(int argc, const char* argv[])
{
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    NSLog(@"Hello from Hello.m!");

    [pool release];
    return 0;
}

//----------

  1. Start MinGW shell. (See above.)

  2. On shell command line, change to directory where program code is located. (Note that, since this is not Unix, the Windows drive letter must be included.):

    cd /c/myprogs/obj-c/hello

  3. Compile the program:

    gcc -o hello hello.m -I/c/GNUstep/GNUstep/System/Library/Headers \

    -L /c/GNUstep/GNUstep/System/Library/Libraries -lobjc -lgnustep-base \

    -fconstant-string-class=NSConstantString

(Note that "\" character allows us to extend command to multiple lines.)

I get the following informational messages when I compile:

Info: resolving ___objc_class_name_NSAutoreleasePool by linking to __imp____objc_class_name_NSAutoreleasePool (auto-import)
Info: resolving ___objc_class_name_NSConstantString by linking to __imp____objc_class_name_NSConstantString (auto-import)

Running resulting hello.exe gives me this:

2009-06-03 14:44:59.483 hello[1240] Hello from Hello.m!
Buggieboy
A: 

I've been banging my head against this with GNUStep under Windows. The simplest tutorials get you to write a C program and compile it with GCC - if I wanted to do that then I wouldn't be bothering with GNUStep. The next level of tutorials do a hello world including the Foundation header and a simple GNUmakefile script, which then doesn't work under the Windows installation as you end up with following the GNUStep instructions. I know to open the shell that it's installed, but following the online tutorials for using a GNUmakefile file still didn't work. You got a whole series of errors from it trying to include the common makefile.

Turns out the solution is pretty easy, you just aren't told to do it. GNUSTEP_MAKEFILES hasn't been set by the installer. If you add an environment variable called GNUSTEP_MAKEFILES with a value of /GNUstep/System/Library/Makefiles and then reopen the shell, then running make in your source folder with a GNUmakefile script can successfully include the common makefile and so on.

This is then enough to get the makefile building a simple console application with the Foundation/Foundation.h header included, which bodes well, although I'll have to investigate further to see whether there's any more settings which haven't been set which affect, say, the GUI side of things.

David Burton
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.
  4. 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.
  5. Now you got the gnustep for windows then go to start>all program> GNUstep> shell
  6. Now open the notepad editor and write the following code in notepad

'#import 'Foundation/Foundation.h'

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
Please format your post!
Nathan Campos
A: 

I'm getting a similar error. Foundation/Foundation.h: No such file or directory.

And i've already installed the two packages in order, and added the environment variable for the makefiles.

I hope somebody produces a simple installation to get working on ObjectiveC on windows XP.

Nosy Rat
A: 

OK I just realised the problem for me with this whole minw32, environment and gnustep core dev and why my make file wasn't working on a windows environment. Because I hadn't used the default options for the location when installing the packages.

Makesure that all the 3 packages are installed on top of each other in the folder structure, as per default options. and I believe it starts in c:\GNUstep\

This solved all the environment problems like:

Foundation/Foundation.h: no such file or directory

objc/Object.h: No such file or directory

Hope if helps anyone else in that cra-py long-winded situation.

Nosy Rat