使用pkg-config与XCB库链接时,GCC提供未定义的引用

问题描述

我正在关注here的X11编程教程。该页面提供了2个可用于编译基于XCB的程序的命令:

gcc -Wall prog.c -o prog `pkg-config --cflags --libs xcb`

gcc -Wall prog.c -lxcb

现在,我都尝试过。第一个gcc: error: unrecognized command-line option ‘--cflags’。显然,这是一个与外壳相关的问题(如我所见here)。所以我尝试了bash。这给出了另一个错误

/usr/bin/ld: /tmp/ccnURTF3.o: in function `useXlib':
example.c:(.text+0xd6): undefined reference to `XInternAtom'
/usr/bin/ld: /tmp/ccnURTF3.o: in function `useXlibProperly':
example.c:(.text+0x163): undefined reference to `XInternAtoms'
/usr/bin/ld: /tmp/ccnURTF3.o: in function `main':
example.c:(.text+0x4b1): undefined reference to `XOpendisplay'
/usr/bin/ld: example.c:(.text+0x559): undefined reference to `XClosedisplay'
collect2: error: ld returned 1 exit status

这与我从gcc -Wall prog.c -lxcb得到的相同。所以我想bash解决了这个问题,但是有2个问题。在Atom中,当您将鼠标悬停在一个函数上时,它会显示它来自哪个标头。但是在这个我什么也没得到。

预先感谢

解决方法

看起来,多年来,库被拆分了,函数声明被移到了另一个库中。现在xcb依赖于X11或类似的东西,或者pkg-config --libs xcb应该输出-lX11,不知道。无论如何,以下工作原理:

gcc -Wall 1.c -lxcb -lX11

或以下内容也适用:

gcc -Wall 1.c $(pkg-config --cflags --libs xcb) $(pkg-config --cflags --libs x11)    

最好ping简介的维护者,让他知道他应该更新页面。