Unable to find standard libraries when compiling Objective-C using GNUstep on Windows
Asked Answered
J

10

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?

Japha answered 25/2, 2009 at 19:20 Comment(1)
You bought Programming in Objective-C 2.0 by Stephen G. Kochan didn't you? Yeah, I ran into this same problem. The author claims he "pays special attention" to how to get this working in Windows, and then NEVER MENTIONS IT ONCE!Fennelflower
N
10

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

Nauseous answered 25/2, 2009 at 19:26 Comment(4)
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).Japha
I got this error: error : cannot find interface declaration for 'NXConstantString'. and got it solved after adding this to compiler: -fconstant-string-class=NSConstantStringCrowfoot
The provided link is returning a 404 error page for me.Prelature
@StevenCraft Try now, link via webarchive now :)Nauseous
T
7

try to run this command line in your command. it worked for me.

gcc -I"c:/GNUstep/GNUstep/System/Library/Headers" -L "c:/GNUstep/GNUstep/System/Library/Libraries" -o hello helloWorld.m -lobjc -lgnustep-base -fconstant-string-class=NSConstantString
Tude answered 2/2, 2012 at 13:59 Comment(0)
K
4

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.

Korfonta answered 4/5, 2009 at 7:17 Comment(2)
I tried it but get errors: $ make -f Test1.make This 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 directory make[1]: *** No rule to make target `GNUmakefile'. Stop. make: *** [Test1.all.tool.variables] Error 2Jennine
To use a different filename than GNUmakefile you must provide both the -f and MAKEFILE_NAME arguments. >> make -f Prog1Makefile MAKEFILE_NAME=Prog1MakefileAbra
O
2

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]

Odellodella answered 21/5, 2010 at 10:2 Comment(2)
I had to use double quotes around "Foundation/Foundation.h", it complains about expecting FILENAME if single quotes are usedDefaulter
This ultimately allowed me to compile.. after changing the source to #import <Foundation/Foundation.h> and changing the compile command to -fconstant-string-class=NSConstantString. Hope that helps someone!Danyluk
B
1

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
Bravura answered 25/2, 2009 at 20:3 Comment(1)
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.Japha
H
1

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!
Harbert answered 3/6, 2009 at 19:32 Comment(0)
H
1

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.

Hyponasty answered 14/10, 2010 at 15:52 Comment(0)
P
1

For my problem the deciding information was

-fconstant-string-class=NSConstantString

from buggieboy above...

Picklock answered 27/4, 2011 at 16:25 Comment(0)
L
1

I know this is a late response, but the following website is great for getting you up and running with GNUstep, with the above and many other questions answered:

http://www.gnustep.it/nicola/Tutorials/index.html

It's helped me a ton.

Lancey answered 23/2, 2012 at 15:53 Comment(0)
L
0

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.

Longheaded answered 29/4, 2010 at 0:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.