刚刚在翻新机(2GB 内存,2GHz 双核)上开始使用 Xubuntu 14.04,并且对 c 有粗略/阅读知识,但我不是 c 程序员。
我正在尝试编译我找到的代码这里为工作区之间移动的操作创建视觉通知。代码:
// 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 包中对象的未定义引用的错误,但这并没有改变任何错误输出。
任何建议将不胜感激!
答案1
参数的顺序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`