Help with compiling a simple plugin for GIMP 3

Hi,

GIMP is compiling ok, next step was to compile a plugin. Please bear in mind my understanding is
as deep as a puddle. Any pointers appreciated! :melting_face:

#include <libgimp/gimp.h>

static void query(void);
static void run(const gchar *name, gint nparams, const GimpParam *param,
                gint *nreturn_vals, GimpParam **return_vals);

GimpPlugInInfo PLUG_IN_INFO = {
  NULL,  // init_proc
  NULL,  // quit_proc
  query, // query_proc
  run    // run_proc
};

MAIN()

static void query(void) {
  static GimpParamDef args[] = {
    {
      GIMP_PDB_INT32, // type
      "run-mode",     // name
      "Run mode"      // description
    }
  };

  gimp_install_procedure(
    "plug-in-hello",                // name
    "Hello",                        // blurb
    "Displays a 'Hello' message",   // help
    "Your Name",                    // author
    "Your Copyright",               // copyright
    "2023",                         // date
    "<Image>/Filters/Hello",        // menupath
    "",                             // imagetypes
    GIMP_PLUGIN,                    // type
    G_N_ELEMENTS(args),             // nparams
    0,                              // nreturn_vals
    args                            // params
  );
}

static void run(const gchar *name, gint nparams, const GimpParam *param,
                gint *nreturn_vals, GimpParam **return_vals) {
  g_message("Hello!");

  *nreturn_vals = 0;
  *return_vals = NULL;
}

This is the contents of a “CMakeLists.txt” file, for some reason I had to add some include directories. Which I thought PkgConfig was for?

cmake_minimum_required(VERSION 3.0)
project(gimp-compiled-plugins)
set(CMAKE_C_STANDARD 11)

include_directories(
  ${GIMP_INCLUDE_DIRS}
  /home/mark/Code/gimp-source/include/gimp-3.0/libgimp;
  /usr/include/cairo;
  /home/mark/Code/gimp-source/build/glib/glib;
  /home/mark/Code/gimp-source/build/glib/gobject
)

find_package(PkgConfig REQUIRED)

# Set the PKG_CONFIG_PATH environment variable
set(ENV{PKG_CONFIG_PATH}
  "/home/mark/Code/gimp-source/lib/x86_64-linux-gnu/pkgconfig \
  :$ENV{PKG_CONFIG_PATH}")

pkg_check_modules(GIMP REQUIRED gimp-3.0)
pkg_check_modules(GIMP REQUIRED gimp-3.0)

link_directories(${GIMP_LIBRARY_DIRS})
add_definitions(${GIMP_CFLAGS_OTHER})
add_executable(hello-world hello-world/src/main.c)
target_link_libraries(hello-world ${GIMP_LIBRARIES})
~/Code/gimp-plugin/gimp-compiled-plugins/build$ cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mark/Code/gimp-plugin/gimp-compiled-plugins/build

Make result:

~/Code/gimp-plugin/gimp-compiled-plugins/build$ make
Consolidate compiler generated dependencies of target hello-world
[ 50%] Building C object CMakeFiles/hello-world.dir/hello-world/src/main.c.o
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:4:56: error: unknown type name ‘GimpParam’
    4 | static void run(const gchar *name, gint nparams, const GimpParam *param,
      |                                                        ^~~~~~~~~
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:5:37: error: unknown type name ‘GimpParam’; did you mean ‘GimpArray’?
    5 |                 gint *nreturn_vals, GimpParam **return_vals);
      |                                     ^~~~~~~~~
      |                                     GimpArray
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:7:1: error: unknown type name ‘GimpPlugInInfo’; did you mean ‘GimpPlugIn’?
    7 | GimpPlugInInfo PLUG_IN_INFO = {
      | ^~~~~~~~~~~~~~
      | GimpPlugIn
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:8:3: warning: initialization of ‘int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
    8 |   NULL,  // init_proc
      |   ^~~~
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:8:3: note: (near initialization for ‘PLUG_IN_INFO’)
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:9:3: warning: excess elements in scalar initializer
    9 |   NULL,  // quit_proc
      |   ^~~~
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:9:3: note: (near initialization for ‘PLUG_IN_INFO’)
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:10:3: warning: excess elements in scalar initializer
   10 |   query, // query_proc
      |   ^~~~~
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:10:3: note: (near initialization for ‘PLUG_IN_INFO’)
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:11:3: error: ‘run’ undeclared here (not in a function); did you mean ‘trunc’?
   11 |   run    // run_proc
      |   ^~~
      |   trunc
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:11:3: warning: excess elements in scalar initializer
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:11:3: note: (near initialization for ‘PLUG_IN_INFO’)
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:14:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
   14 | MAIN()
      | ^~~~
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c: In function ‘MAIN’:
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:16:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
   16 | static void query(void) {
      |                         ^
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:41:56: error: unknown type name ‘GimpParam’
   41 | static void run(const gchar *name, gint nparams, const GimpParam *param,
      |                                                        ^~~~~~~~~
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:42:37: error: unknown type name ‘GimpParam’; did you mean ‘GimpArray’?
   42 |                 gint *nreturn_vals, GimpParam **return_vals) {
      |                                     ^~~~~~~~~
      |                                     GimpArray
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:48: error: expected ‘{’ at end of input
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c: At top level:
/home/mark/Code/gimp-plugin/gimp-compiled-plugins/hello-world/src/main.c:3:13: warning: ‘query’ used but never defined
    3 | static void query(void);
      |             ^~~~~
make[2]: *** [CMakeFiles/hello-world.dir/build.make:76: CMakeFiles/hello-world.dir/hello-world/src/main.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/hello-world.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

You seem to be trying to build a GIMP 2 type plug-in for GIMP 3 (2.99). That won’t work.

We don’t have plug-in templates or tutorials for future GIMP 3 yet. However, you could use the c goat extension which is intended as an example, see https://gitlab.gnome.org/GNOME/gimp/-/blob/master/extensions/goat-exercises/goat-exercise-c.c

In the same folder as the C example, there are also examples if you want to try out a plug-in using Python, Lua, Vala and Javascript.

Basically, you need a class init function that defines the names of your query_procedures and create_procedures functions.

Then your query_procedures function needs to return the names of your publicly available procedure(s); and create_procedures will tell GIMP what parameters are used for each of these procedures, and the name of the function to be called to run that procedure.

The answer is create a plugin within the GIMP repository, using the goat-exercise as a “hello world” example. Then build GIMP, that will also build the plugin.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.