Unable to Compile Objective C using Gnustep on windows

痞子三分冷 提交于 2019-12-06 09:38:39

No need to create a makefile. If you start MinGW from "All Programs -> GNUstep -> Shell" as Pax indicates above, you can just compile your .m file.

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!

That problem just looks like you haven't instructed gcc on where to find the relevant include files (i.e., the directory in which Foundation/Foundation.h resides).

Are you running gcc from under MinGW or from the command prompt. You should have a "All Programs -> GNUstep -> Shell" on your Start menu which brings up this shell.

A makefile for this should be as simple as:

include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = YourProg
YourProg_OBJC_FILES = source_code.m
include $(GNUSTEP_MAKEFILES)/tool.make

If you will put your source codes into home directory in GNUStep, you don't need to provide relative location of Foundation framework.

Using a makefile such as the one specified by paxdiablo is probably the easiest, because rather than trying to remember an arcane command line each time, you set up the makefile and then call make from the source folder. However, my experience under Windows suggested that GNUStep and Windows, even with the shell, won't build using that because it can't find all the make files it needs - add an environment variable GNUSTEP_MAKEFILES with a value of /GNUstep/System/Library/Makefiles and restart that shell, and then any errors from it being unable to find the standard makefiles should be history. (I had tried using full paths to the makefiles, but found that this included the specific makefiles but then failed when trying to include further ones, hence going the easy route and adding an environment variable.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!