我可能在這里遺漏了一些非常基本的東西,但由于某種原因,我無法在我的 Ubuntu 20.04 系統上成功鏈接 libnotify,即使一切都正確安裝并且 pkg-cfg(恕我直言)回傳了正確的選項......任何想法?
user@home:~/jabrac$ ldconfig -v | grep notify
libnotify.so.4 -> libnotify.so.4.0.0
user@home:~/jabrac$ dpkg -L libnotify-dev
/.
/usr
/usr/include
/usr/include/libnotify
/usr/include/libnotify/notification.h
/usr/include/libnotify/notify-enum-types.h
/usr/include/libnotify/notify-features.h
/usr/include/libnotify/notify.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/libnotify.pc
/usr/share
/usr/share/doc
/usr/share/doc/libnotify-dev
/usr/share/doc/libnotify-dev/copyright
/usr/share/gir-1.0
/usr/share/gir-1.0/Notify-0.7.gir
/usr/lib/x86_64-linux-gnu/libnotify.so
/usr/share/doc/libnotify-dev/changelog.Debian.gz
user@home:~/jabrac$ ls -l /usr/lib/x86_64-linux-gnu/libnotify.so*
lrwxrwxrwx 1 root root 14 M?r 20 2020 /usr/lib/x86_64-linux-gnu/libnotify.so -> libnotify.so.4
lrwxrwxrwx 1 root root 18 M?r 20 2020 /usr/lib/x86_64-linux-gnu/libnotify.so.4 -> libnotify.so.4.0.0
-rw-r--r-- 1 root root 38984 M?r 20 2020 /usr/lib/x86_64-linux-gnu/libnotify.so.4.0.0
user@home:~/jabrac$ cat hello_world.c
#include <libnotify/notify.h>
#include <stdio.h>
int main(int argc, char * argv[] )
{
notify_init("Sample");
NotifyNotification* n = notify_notification_new ("Hello world",
"some message text... bla bla",
0);
notify_notification_set_timeout(n, 10000); // 10 seconds
if (!notify_notification_show(n, 0))
{
printf("show has failed\n");
return -1;
}
return 0;
}
user@home:~/jabrac$ gcc `pkg-config --cflags --libs libnotify` hello_world.c
/usr/bin/ld: /tmp/cckbaX1n.o: in function `main':
hello_world.c:(.text 0x1b): undefined reference to `notify_init'
/usr/bin/ld: hello_world.c:(.text 0x33): undefined reference to `notify_notification_new'
/usr/bin/ld: hello_world.c:(.text 0x48): undefined reference to `notify_notification_set_timeout'
/usr/bin/ld: hello_world.c:(.text 0x59): undefined reference to `notify_notification_show'
collect2: error: ld returned 1 exit status
user@home:~/jabrac$ pkg-config --cflags --libs libnotify
-pthread -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lnotify -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
uj5u.com熱心網友回復:
正如@Someprogrammerdude 上面所說,您需要在程式之后指定 -l 選項。以下是 gcc(1) 手冊頁中的相關部分:
-llibrary
...
在命令中撰寫此選項的位置有所不同;聯結器按照指定的順序搜索和處理庫和目標檔案。因此,foo.o -lz bar.o 在檔案 foo.o 之后但在 bar.o 之前搜索庫 z。如果 bar.o 參考 z 中的函式,則可能不會加載這些函式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/372487.html
上一篇:從.NETCore2.2遷移到.NETCore3.1-在LINQ中DefaultIfEmpty()不轉換問題
下一篇:沒有參考glib函式
