即使包含glib,对glib组件的未定义引用错误


0

刚在经过翻新的机器(2GB内存,2GHz双核)上以Xubuntu 14.04入手,并且对c具有粗略的/读过的知识,但不是ac程序员。

我正在尝试编译在这里找到的代码以便为在工作空间之间移动的行为创建可视通知。编码:

// 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;
}

编译命令:

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

我收到的错误:

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

我拥有最新版本的libwnck,并且还添加了:

#include <glib.h>

看看这是否可以解决似乎源自对glib包中对象的未定义引用的错误,但这并没有更改任何错误输出。

任何建议将不胜感激!

Answers:


2

参数的顺序gcc很重要,因此您需要拆分调用的--cflags--libs变体pkg-config

gcc -O2 -DWNCK_I_KNOW_THIS_IS_UNSTABLE -o wschanged `pkg-config --cflags libwnck-3.0` wschanged.c `pkg-config --libs libwnck-3.0`
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.