Whole document tree ![]() ![]() ![]() ![]() ![]()
GUM v.1.0.041Compiling plug-insIn this chapter will we try to explain how to compile plug-ins so they can be used in Gimp.What is a plug-in?A plug-in is a program that can't run on its own, it needs to be started by Gimp. Compile?Most of the time, plug-ins are distributed in the source code. All programs have a source code (if they aren't written directly in machine code). The source code is written in a language humans can understand, like C, C++ etc... The computer doesn't understand C or C++, so the code needs to be translated to machine code which the computer understands and can execute. This translation is called compiling. What way to go when you want to compileThere are three common ways to compile; Make, Configure and Plain cc. This is not totally correct, but it's good enough for now. You can also use gimp-tool to build and install a plugin if it's only one .c file see appendix B. Make is a program which takes a specification file, commonly called Makefile, and by running this file it compiles the program with the help of the compiler. Configure is a program that generates a Makefile. After doing this you will have to run Make in order to compile. The most simple way is to use the compiler directly to compile the code. We will try to explain how to handle these three types of compiling. But before we start, we must tell you that we can't cover every angle or error that can arise when you compile. We will cover the basics, but not extras like special compiler flags, debugging etc. We really want you to try to compile a plug-in even if you aren't a programmer or hacker. If you have a friend who is a Unix programmer, we still think you should read this chapter and try to compile, and if it goes totally wrong anyway, call in your mate. How to obtain and install the source codeMost of the time, you will go to the plug-in registry or the Unpacking the source codeWhen you have downloaded the source code, you must unpack it. Usually, the code ends with If the source ends with Compiling the codeWe will use GNU tools to compile the code. If you are using a system that doesn't have GNU tools installed, then you have two options: either download and install GNU tools (beyond the scope of this book) or use the system's own tools. There is no big difference between GNU and system tools. Some of the GNU tools can be recognized by the fact that their names start with the letter g. For example, the GNU compiler is called gcc and the system's own compiler is called cc. We think that this won't make any difference here, but we can't be sure because there are a lot of different Unix systems out there, and we cant cover them all. Finding out how to compile the plug-inWhen you have downloaded and unpacked the plug-in source, you have to find out how to compile it. The plug-in are often packed with several other files. Sometimes there is a Most of the time, you will find information on how to compile and install the plug-in in one of these files. You can also take a look in the head of the C code file. If there is no information, then you have to follow our examples here, and even if you do find some information, you are advised to read on. The You can most likely find out if you have this libraries, or other required programming by reading the chapter about installing the source distribution of Gimp in Chapter 4. Compiling a library is a bit different than compiling a plug-in., but the start is basically the same, so keep on reading. If the plug-in you've downloaded is a single file, or if the archive you just unpacked has no Makefile (it can be named Makefile, Makefile.classic, MAKEFILE etc.) or configure file, then you have to compile it directly with gcc or you have to create a Makefile or configure script. If there is a Makefile then you can use make to compile the plug-in. But before you begin, you have to check and perhaps edit the Makefile to find out whether it is correct for your system. If there is a configure script, then use it to generate a Makefile Using GCC to compile the plug-in straight offA first tryIf the file is named Here is an example of what happens if you compile the waterselect.c file this way: (only some of the lines) / LibrariesThis happens when the libraries needed aren't linked to the executable that you are trying build. A library is a set of functions, for example a function which creates a window or a scrollbar. The plug-in will call different functions in these libraries, like the function Another tryNow let's try to compile it with Include fileThe error messages telling you that an include (header file) is missing goes like this: waterselect.c:39: gtk/gtk.h: No such file or directory What does this message really mean? It says that a file named
We have to tell the compiler where to search for the file. We can do that by adding a gcc -o plug-in plugin.c -L/usr/local/lib -lgimp -lgtk -I/usr/local/include The T he -L flag and how to find out which libs to linkThe -L flag works the same way. It tells the compiler where to search for libraries, in this case the libraries How do we know which libraries to add and which directories to include? We have to take a look inside the code to get a hint about what to add (generally located in the beginning of the file). Here's an example from the #include <stdlib.h> #include <stdio.h> #include <math.h> #include <gtk/gtk.h> #include "libgimp/gimp.h" This code tells us that the compiler will include five files when it compiles the code. The first three are ordinary standard C include files, and the other ones are special Gimp and gtk files. The -I flagThe standard C header files are in located in a standard include directory, which the compiler will search. However, the The source code lines can also give us a hint on which libraries to link with; in this case What to do when there are several source filesNow we've hopefully learned how to compile a plug-in that is made up of a single C source code file. However, a plug-in can be contain more that one C source code file. How do we compile such plug-ins?. If the extra file is a header file, (named What should you do if the plug-in is built up of several files? (like this plugin:. What we need to do is to make object files out of each part. These object files will then be linked together, thus creating the final executable plug-in. We will give you an example: gcc -c pluginmain.c -I/usr/local/include gcc -c pluginpart1.c -I/usr/local/include gcc -c pluginpart2.c -I/usr/local/include gcc -o plug-in pluginmain.o pluginpart1.o pluginpart2.o -L/usr/local/lib -lgtk -lgimp -lgimpui -lmpeg The first three lines is where we make the object files. We tell the compiler to make object files by adding the The last line is where we make the final plug-in. Here, we don't need to worry about include files. We only have to make sure that we link the libraries needed by the plug-in. We can look at it this way: when we make the object files, we include descriptions of library function calls by including header files. The plug-in object file will happily use them, because it assumes that it will be linked to these libraries later on. This is what happens in the last line: Here we tell the compiler that the final outcome will be a plug-in. We do this by adding A big program or plug-in can consist of several parts. If your dealing with such a plug-in, compiling the different parts manually is often the wrong way to go. The reason for this is that if something goes wrong, you will have to type all your commands again. The solution is to create a Makefile. A Makefile is a specification which the Make command uses as an input to compile the entire plug-in with the help of the compiler. How to create a Makefile and how to use itNow we'll take a look at how to create a simple Makefile. This will help us understand the structure of a Makefile, so that we'll know how to edit a Makefile which comes with a plug-in. We will take a quick look at a generic Makefile CC = gcc INCDIR = -I/usr/local/include -I/usr/local/tiff/include CFLAGS = -O2 LIBDIR = -L/usr/X11/lib -L/usr/local/lib LFLAGS = -lgimp -lgtk -lX11 -ltiff -lgimpui HEDERS = plugin.h plugin2.h SOURCES = pluginmain.c pluginpart1.c pluginpart2.c OBJECTS = pluginmain.o pluginpart1.o pluginpart2.o plug-in: $(OBJECTS) $(HEADERS) $(CC) $(CFLAGS) -o $@ $(OBJECTS) $(INCDIR) $(LIBDIR) $(LFLAGS) This Makefile will first build the object files, and then link the plug-in. All you have to do if you want to use it is to replace the header, object, and source files with the correct ones. You can also change what libs to link, and what directories to search for libs and includes. The Makefile:11: *** missing separator. Stop. A Makefile exampleHere's how the Makefile looked when we built the Guash plug-in at our Linux system (there is a Makefile included in the distribution of Guash, this example is only for training) CC = gcc INCDIR = -I/usr/local/include CFLAGS = -O2 LIBDIR = -L/usr/local/lib LFLAGS = -lglib -lgdk -lgtk -lgimp HEADERS = guash-directory.h guash-banner.h SOURCES = guash.c OBJECTS = guash.o guash: $(OBJECTS) $(HEADERS) $(CC) $(CFLAGS) -o $@ $(OBJECTS) $(INCDIR) $(LIBDIR) $(LFLAGS) The important thing is to change, and maybe add include and library directories so it will fit your system. We hope you're now able to edit a Makefile so it will fit your system. You have to remember that you can write a Makefile in several different ways, this is only one of many. VariablesWhen you edit another makefile it may not look like this, but with the basic knowledge and the knowledge of how to compile by hand, you should be able to edit it. As you see, the first eight lines are variables which are called later in line 10 and 11 with To build the plug-in, simply invoke Make by typing A common error when you compile a plug-in which comes as an archive with a Makefile, is that the Make-program complains about dependencies. If so, remove the.deps directory ( Configure a way to automate the building processThe configure script that comes with the plug-in is a way to automate the process of making a Makefile. This script will try to find the include files and libraries that the plug-in needs. If you are on a common UNIX platform like Solaris, Linux etc. then it's generally quite simple to use a configure script. To build your plug-in, type the following in the directory where you unpacked the plug-in: If you don't have a certain file or lib, or the script can't find it, then you have to install it or tell the script where to find it.
To find out how to tell the script where to find include files and libraries etc. invoke the script like this: --libdir=DIR --includedir=DIR With these two flags you can add an include/library dir like this export CFLAGS="-I/one/includedir -I/another/includedir" If you are working in a C shell, then you have to do it like this: setenv CFLAGS "-I/one/includedir -I/another/includedir" If you want to add more than one libdir, type the same as for the CFLAGS, but write LDFLAGS instead. Configure is not bullet-proof, and you may run into several problems, especially if you are using a UNIX dialect which is different from what the configure authors were working on. If you run into this kind of problems, first try to add all the lib and include dirs to the script with the FLAGS, or to add them by hand in the generated Makefile. If this still doesn't solve the problem, try writing a mail to the Gimp mailing list. Generated by fmtoweb (v. 2.9c) written by Peter G. Martin <peterm@zeta.org.au> Last modified: 20 May 1998
|