gpt4 book ai didi

c - gcc - 错误编译示例 xscreensaver

转载 作者:太空宇宙 更新时间:2023-11-04 02:04:22 25 4
gpt4 key购买 nike

我正在尝试编译示例屏幕保护程序 simplesquares.c(来自 here)。我有 vroot.h,这是我正在使用的命令:

gcc -lX11 -o simplesquares simplesquares.c

这些是返回的错误:

/tmp/cc0FvxcU.o: In function `VirtualRootWindowOfScreen':
simplesquares.c:(.text+0x55): undefined reference to `XInternAtom'
simplesquares.c:(.text+0x82): undefined reference to `XQueryTree'
simplesquares.c:(.text+0x108): undefined reference to `XGetWindowProperty'
simplesquares.c:(.text+0x14c): undefined reference to `XFree'
/tmp/cc0FvxcU.o: In function `main':
simplesquares.c:(.text+0x17b): undefined reference to `XOpenDisplay'
simplesquares.c:(.text+0x1c8): undefined reference to `XCreateGC'
simplesquares.c:(.text+0x201): undefined reference to `XSetForeground'
simplesquares.c:(.text+0x295): undefined reference to `XFillRectangle'
simplesquares.c:(.text+0x2e3): undefined reference to `XClearWindow'
simplesquares.c:(.text+0x2ef): undefined reference to `XFlush'
collect2: error: ld returned 1 exit status

这里发生了什么,我该如何解决?

最佳答案

静态链接库应该在命令行的末尾。

gcc -o simplesquares simplesquares.c -lX11

来自 http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html :

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.

关于c - gcc - 错误编译示例 xscreensaver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22522228/

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