Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 解析未定义的引用xcb_C++_C_Undefined Reference_Xcb - Fatal编程技术网

C++ 解析未定义的引用xcb

C++ 解析未定义的引用xcb,c++,c,undefined-reference,xcb,C++,C,Undefined Reference,Xcb,我可以包括xcb/xcb.h中的项目,但不能包括/usr/include/xcb/randr.h中概述的项目 我的首选是使用C++,但是为了帮助调试,我也尝试了C,它产生了相同错误的变化。 我肯定我做了一些不正确的事情,但我不确定从哪里着手解决这个问题。非常感谢您的阅读,有什么建议吗 例子 main.cpp #包括 #包括 int main() { 常数xcb_设置*x设置; xcb_连接接头; xcb_screen_t*屏幕; xcb_window_t root_win; xcb\u屏幕迭代器

我可以包括
xcb/xcb.h
中的项目,但不能包括
/usr/include/xcb/randr.h
中概述的项目

我的首选是使用C++,但是为了帮助调试,我也尝试了C,它产生了相同错误的变化。 我肯定我做了一些不正确的事情,但我不确定从哪里着手解决这个问题。非常感谢您的阅读,有什么建议吗

例子 main.cpp
#包括
#包括
int main()
{
常数xcb_设置*x设置;
xcb_连接接头;
xcb_screen_t*屏幕;
xcb_window_t root_win;
xcb\u屏幕迭代器\u t屏幕迭代器;
xcb\u randr\u get\u screen\u resources\u cookie\t resources;
//连接到Xserver
conn=xcb_connect(空,空);
xsetup=xcb_get_设置(conn);
//获取根窗口
screen_iterator=xcb_setup_root_iterator(xsetup);
screen=screen_iterator.data;
root\u win=屏幕->根目录;
//xcb/randr.h中的任何函数在引用未定义的情况下失败。
资源=xcb\u randr\u get\u screen\u资源(conn,root\u win);
}
编撰
#gcc尝试
gcc-Wall main.cpp-o main`pkg config--cflags--libs xcb`
g++-Wall main.cpp-o main`pkg config--cflags--libs xcb`
#叮当声
clang++main.cpp-o main`pkg config--cflags--libs xcb`
clang main.cpp-o main`pkg config--cflags--libs xcb`
结果
gcc

/usr/bin/ld:/tmp/ccWR2GQL.o:在函数“main”中:
main.cpp:(.text+0x6c):对'xcb\u randr\u get\u screen\u resources'的未定义引用
collect2:错误:ld返回了1个退出状态
clangg

/usr/bin/ld:/tmp/main-d114b5.o:在函数“main”中:
main.cpp:(.text+0x67):对“xcb\u randr\u get\u screen\u资源”的未定义引用
clang-7:错误:链接器命令失败,退出代码为1(使用-v查看调用)

xcb库被分成几个不同的包;因此,您需要同时引入
xcb
xcbrandr
库,明确地:

... `pkg-config --cflags --libs xcb xcb-randr`

您的Linux发行版可能会单独打包randr库。检查Fedora,它将xcb和xcb rand都打包在
libxcb-devel
子包中;但是您的Linux发行版可能有一个单独的
libxcb randr-devel
子包需要安装。

非常感谢
n.m.
G.m.

我没有链接
xcbrandr

解决方案:

clang++main.cpp-o main`pkg config--cflags--libs xcb`-lxcb randr

pkg-config--cflags--libs-xcb的输出是什么?
pkg-config--cflags--libs-xcb
返回
-lxcb
Randr在一个单独的库中,可能称为libxcb-Randr。但是您需要在link命令中链接它:
-lxcb-Randr
。非常感谢,这解决了我的问题。对不起,我对编译语言非常陌生。