解决未定义的参考XCB
resolving undefined references xcb
i可以包括xcb/xcb.h
中的项目,但不能包括/usr/include/xcb/randr.h
中概述的项目。
我的偏爱是使用C ,但是为了帮助调试我也尝试了C,从而产生了相同错误的变化。
我敢肯定我在做一些错误的事情,但是我不确定从哪里开始寻求解决这个问题。非常感谢您的阅读,任何建议?
示例
main.cpp
#include <xcb/xcb.h>
#include <xcb/randr.h>
int main()
{
const xcb_setup_t * xsetup;
xcb_connection_t * conn;
xcb_screen_t * screen;
xcb_window_t root_win;
xcb_screen_iterator_t screen_iterator;
xcb_randr_get_screen_resources_cookie_t resources;
// connect to Xserver
conn = xcb_connect(NULL, NULL);
xsetup = xcb_get_setup(conn);
// get the root window
screen_iterator = xcb_setup_roots_iterator(xsetup);
screen = screen_iterator.data;
root_win = screen->root;
// any function from xcb/randr.h fails with undefined reference.
resources = xcb_randr_get_screen_resources(conn, root_win);
}
编译
# gcc tries
gcc -Wall main.cpp -o main `pkg-config --cflags --libs xcb`
g++ -Wall main.cpp -o main `pkg-config --cflags --libs xcb`
# clang tries
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: in function `main':
main.cpp:(.text+0x6c): undefined reference to `xcb_randr_get_screen_resources'
collect2: error: ld returned 1 exit status
clang
/usr/bin/ld: /tmp/main-d114b5.o: in function `main':
main.cpp:(.text+0x67): undefined reference to `xcb_randr_get_screen_resources'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
XCB库以几个不同的软件包分配;因此,您需要显式地拉动xcb
和xcb-randr
库:
... `pkg-config --cflags --libs xcb xcb-randr`
您的Linux发行版可能会分别包装Randr库。检查Fedora,它在libxcb-devel
子包中包装XCB和XCB-Rand;但是您的Linux发行版可能需要安装单独的libxcb-randr-devel
子弹。
非常感谢n.m.
和G.M.
。
我没有链接xcb-randr
。
解决方案:
clang++ main.cpp -o main `pkg-config --cflags --libs xcb` -lxcb-randr
相关文章:
- C++错误消息*成员参考.**初学者*
- 在决定是通过参考还是通过价值时,尺寸真的是一个问题吗
- 参考资源文件VC++中的$(SolutionDir)
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 为什么在运算符重载时需要参考?
- 使 \page 和 \subpage 参考 doxygen 中的方法文档
- std::shared_ptr 自定义参考计数器
- 英特尔 TBB 程序不会终止,可能会误用参考计数器
- 避免在基于反向范围的for循环实现中悬挂参考
- 通用参考 l 值不复制对象
- 标准::enable_if和通用参考的使用差异
- 标准::积累参考?
- C++丢失了参考
- 我可以有一个 ELI5 作为参考和指针以及何时使用它们吗?
- 矢量的通用参考
- 为什么"fun(i)"被推导出为"fun<int&>"而不是"fun<int>",因为"i"是"int"的类型而不是参考?
- C++17 和静态临时生存期的参考扩展
- C++ 参考:这两个语句有什么区别?
- 如何理解 C++17 标准参考中的 [intro.object]/3? N4659 的
- 解决未定义的参考XCB