gpt4 book ai didi

c - 编译 BASIC "libnotify"代码时出错

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:42:51 26 4
gpt4 key购买 nike

#include <libnotify/notify.h>
#include <glib.h>
#include <unistd.h>
int main(int argc, char** argv)
{
if(argc == 3)
{
NotifyNotification *n;
notify_init("Test");
n = notify_notification_new (argv[1],argv[2], NULL, NULL);
notify_notification_set_timeout (n, 3000); //3 seconds
if (!notify_notification_show (n, NULL)) {
g_error("Failed to send notification.\n");
return 1;
}
g_object_unref(G_OBJECT(n));
}else{
g_print("Too few arguments (%d), 2 needed.\n", argc-1);
}
return 0;
}

编译代码给我“undefined reference to”错误:

shadyabhi@shadyabhi-desktop:~/c$ gcc -Wall -o test libnotify.c `pkg-config --libs --cflags glib-2.0 gtk+-2.0`
/tmp/ccA2Q6xX.o: In function `main':
libnotify.c:(.text+0x20): undefined reference to `notify_init'
libnotify.c:(.text+0x4b): undefined reference to `notify_notification_new'
libnotify.c:(.text+0x60): undefined reference to `notify_notification_set_timeout'
libnotify.c:(.text+0x71): undefined reference to `notify_notification_show'
collect2: ld returned 1 exit status
shadyabhi@shadyabhi-desktop:~/c$

我从这个 blog 中获取了代码.

最佳答案

听起来您忘记传递 -lnotify 以实际链接到 libnotify。

关于c - 编译 BASIC "libnotify"代码时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2329905/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com