You are here

How to build a GIMP plug-in with Visual Studio

It's easy, and thankfully doesn't involve building GIMP itself.

  1. Install Visual Studio or Visual C++ Express. I use C++ Express 2010.
  2. Download the sources for GIMP and GTK+ (go for the bundle).
  3. Grab all of the .def files from the GIMP source tree, and grab all of the compiled DLLs from your GIMP install, and put them into the same folder. Rename the defs to match the DLLs (e.g. gimp.def to libgimp-2.0-0.def). To build a plug-in with UI you will need at least these:
    • intl
    • libgimp-2.0-0
    • libgimpbase-2.0-0
    • libgimpui-2.0-0
    • libgimpwidgets-2.0-0
    • libglib-2.0-0
    • libgobject-2.0-0
    • libgtk-win32-2.0-0

    Libs for glib, gobject and gtk-win32 can be found ready-made in the GTK source tree.

  4. Open the Visual Studio Command Prompt and run this command for each def: lib /def:whatever.def /out:whatever.lib /machine:x86. This will generate static libraries that you can link against.
  5. Create an empty VS project. Add a CPP file and change its extension to just C.
  6. Open project properties and make these changes:
    C > General > Additional Include Directories
    C:\gimp-2.6.11;C:\gtk+-2.22.0\include\glib-2.0;C:\gtk+-2.22.0\lib\glib-2.0\include;C:\gtk+-2.22.0\include;C:\gtk+-2.22.0\include\gtk-2.0;C:\gtk+-2.22.0\include\cairo;C:\gtk+-2.22.0\include\pango-1.0;C:\gtk+-2.22.0\lib\gtk-2.0\include;C:\gtk+-2.22.0\include\gdk-pixbuf-2.0;C:\gtk+-2.22.0\include\atk-1.0
    Linker > System > SubSysytem
    Windows (/SUBSYSTEM:WINDOWS) (prevents a console window from briefly popping up)
    Build Events > Post-Build Event
    copy "$(TargetPath)" "$(USERPROFILE)\.gimp-2.6\plug-ins\"
  7. Drag all of your libs onto the Solution Explorer, or add them by hand through Linker properties.

Unless I've forgotten something you can now build a Windows plug-in. Just bear in mind that you're writing C code, which has some limitations compared to C++ (like requiring variables to be declared at the top of code blocks). In theory C++ can be used, but I never worked out how to solve the errors trying to compile CPP files creates.

Debugging isn't straightforward because you are compiling separate executables, which the VS debugger won't catch when GIMP launches them. If you have Visual Studio you can use the just-in-time debugger, but if you've got C++ Express you don't have that luxury. I've found that the best solution is this:

#ifdef _DEBUG
// Poor man's JIT debugger!
while(1) {}
#endif

Start your plug-in, use Attach to Process, pause execution, then drag the yellow arrow out of the loop manually. You may need to add _DEBUG to your preprocessor definitions manually too (in Debug mode only, as this trick won't work in Release builds).

Subscribe to Comments for "How to build a GIMP plug-in with Visual Studio"