Next: 2.3 Linking against an Up: 2 Libraries Previous: 2.1 Compiling A Library

2.2 Linking your app or tool against a GNUstep library

In our first example, we want to write a tiny tool which uses our libHelloWorld. The tool source code is in the file main.m, which is the following:
#include <Foundation/Foundation.h>
#include <HelloWorld/HelloWorld.h>

int main (void)
{
  [HelloWorld printMessage];

  return 0;
}
(We invoke the printMessage method of the HelloWorld class, then exit.).

We write our usual GNUmakefile (but including GNUmakefile.preamble):

include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = HelloWorldTest
HelloWorldTest_OBJC_FILES = main.m

include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/tool.make

Then, here is the GNUmakefile.preamble, in which we tell the make package about the library we want to link against:

HelloWorldTest_TOOL_LIBS += -lHelloWorld

If you have correctly installed the library HelloWorld, this is all you need to do. If you needed to link against more than one library, you would simply put them on the same line, as in:

HelloWorldTest_TOOL_LIBS += -lHelloWorld -lHelloMoon
which links against the two libraries HelloWorld and HelloMoon.

If HelloWorld were an application, you would need to use

HelloWorldTest_GUI_LIBS += -lHelloWorld
(the difference is GUI instead of TOOL).



2010-03-12