Just starting out with Xubuntu 14.04 on a refurbished machine (2GB mem, 2GHz dual core), and have a cursory/reading knowledge of c, but am not a c programmer.

I'm trying to compile code I found here to create a visual notification for the action of moving between workspaces. The code:

// wschanged.c
#include <libwnck/libwnck.h>
#include <stdlib.h>

static void
on_active_workspace_changed (WnckScreen    *screen,
                             WnckWorkspace *space,
                             gpointer      data)
    // Executes a script on workspace change
    system ("~/.workspace-changed");

int main(int argc, char ** argv)

   GMainLoop *loop;   
   WnckScreen *screen;

   glib:gdk_init (&argc, &argv);

   loop = g_main_loop_new (NULL, FALSE);
   screen = wnck_screen_get_default();

   g_signal_connect (screen, "active-workspace-changed",
                    G_CALLBACK (on_active_workspace_changed), NULL);

   g_main_loop_run (loop);
   g_main_loop_unref (loop);    

   return 0;

The compile command:

gcc -O2 -DWNCK_I_KNOW_THIS_IS_UNSTABLE -o wschanged `pkg-config  --cflags --libs libwnck-3.0` wschanged.c

The errors I'm receiving:

wschanged.c: In function ‘on_active_workspace_changed’:
wschanged.c:12:12: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result [-Wunused-result]
     system ("~/.workspace-changed");
/tmp/ccR60OkB.o: In function `main':
wschanged.c:(.text.startup+0x16): undefined reference to `gdk_init'
wschanged.c:(.text.startup+0x1f): undefined reference to `g_main_loop_new'
wschanged.c:(.text.startup+0x27): undefined reference to `wnck_screen_get_default'
wschanged.c:(.text.startup+0x41): undefined reference to `g_signal_connect_data'
wschanged.c:(.text.startup+0x49): undefined reference to `g_main_loop_run'
wschanged.c:(.text.startup+0x51): undefined reference to `g_main_loop_unref'
collect2: error: ld returned 1 exit status

I have the latest version of libwnck, and I've also added:

#include <glib.h>

to see if this would fix the errors seeming to stem from undefined references to objects in the glib package, but this has not changed any of the error output.

Any suggestions would be greatly appreciated!


The order of arguments to gcc is significant, so you need to split the --cflags and --libs variants of the pkg-config invocations:

gcc -O2 -DWNCK_I_KNOW_THIS_IS_UNSTABLE -o wschanged `pkg-config --cflags libwnck-3.0` wschanged.c `pkg-config --libs libwnck-3.0`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.