Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuming you have installed GNUstep correctly and your environment is set up (all explained in the documentation) then you actually need to create a blank GNUmakefile in the root directory of your project and list your sources in that.</p> <p>Here's a simple "Hello World" command line example:</p> <p>Create a directory to contain your source code. HelloWorld would be a good idea.</p> <p>In that, create files <code>main.m</code>, <code>Greeter.m</code> and <code>Greeter.h</code>.</p> <p>We'll create the <code>Greeter</code> class which will just have one method <code>-sayHelloToRecipient:</code>.</p> <p>In the <code>Greeter.h</code>:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface Greeter : NSObject { } -(void)sayHelloToRecipient:(NSString *)recipientName; @end </code></pre> <p>And in the <code>Greeter.m</code>:</p> <pre><code>#import "Greeter.h" @implementation Greeter -(void)sayHelloToRecipient:(NSString *)recipientName { NSLog(@"Hello %@!", recipientName); } @end </code></pre> <p>Your <code>main.m</code> file simply includes the <code>Greeter</code> and invokes it with the argument <code>@"World"</code>.</p> <pre><code>#import "Greeter.h" int main(void) { Greeter *greeter = [[Greeter alloc] init]; [greeter sayHelloToRecipient:@"World"]; [greeter release]; return 0; } </code></pre> <p>Now you've got your sources ready to build, you just need to <em>create</em> a <code>GNUmakefile</code>. Make an empty file, and start it with the line: <code>include $(GNUSTEP_MAKEFILES)/common.make</code>, ending with the line <code>include $(GNUSTPEP_MAKEFILES)/tool.make</code>.</p> <p>The first line includes all the other makefiles and targets GNUstep provides. The last line includes the makefiles needed to produce a command line tool. If you were build a GUI app you'd include <code>application.make</code>. For frameworks you'd include <code>framework.make</code> etc.</p> <pre><code>include $(GNUSTEP_MAKEFILES)/common.make # Your project-specific directives will go here include $(GNUSTEP_MAKEFILES)/tool.make </code></pre> <p>The stuff you put between these lines is the stuff that changes from project to project.</p> <p>The complete <code>GNUmakefile</code> looks like this:</p> <pre><code>include $(GNUSTEP_MAKEFILES)/common.make HELLO_ROOT_DIR = $(abspath .) GNUSTEP_BUILD_DIR = $(HELLO_ROOT_DIR)/build TOOL_NAME = HelloWorld HelloWorld_OBJC_FILES = \ Greeter.m \ main.m include $(GNUSTEP_MAKEFILES)/tool.make </code></pre> <p><code>HELLO_ROOT_DIR</code> is entirely optional and is just a variable that saves me from having to re-type the path to the root as the project grows (and so does the complexity of the makefile).</p> <p><code>TOOL_NAME</code> is required for a command line tool and specifies both the output filename, and determines what you need to use for the <code>*_OBJC_FILES</code> line (i.e. in this case I need to use <code>HelloWorld_OBJC_FILES</code> because <code>TOOL_NAME</code> is "HelloWorld".</p> <p>With this in place, provided you're in the same directory as the makefile, you should be able to just type `make' to build the tool. It will create a "build" directory and inside that you'll find the executable. This one when invoked just outputs:</p> <pre><code>-$ ./build/obj/HelloWorld 2010-11-28 03:36:28.459 HelloWorld[12949] Hello World! </code></pre> <p>None of this will work however if your environment is not configured correctly. I've never done this on Windows, but I assume the same principles apply. That's running a shell script on Linux/UNIX (running batch file on Windows?) in order to configure the environment.</p> <pre><code>-$ . /usr/share/GNUstep/Makefiles/GNUstep.sh </code></pre> <p>You can check if it's correctly configured by printing the environment variable <code>GNUSTEP_MAKEFILES</code> to the console:</p> <pre><code>-$ echo $GNUSTEP_MAKEFILES </code></pre> <p>(Not sure how you do this on Windows)</p> <p>If it outputs nothing, your environment is not correctly configured and/or GNUstep is not correctly installed. If it outputs a path, you should be safe to run `make'.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload