GCC - 错误编译例子的xscreensaver [英] gcc - errors compiling example xscreensaver
问题描述
我想在这里编译示例屏幕simplesquares.c(从 )。我有vroot.h,这是我使用的命令:
I'm trying to compile the example screensaver simplesquares.c (from here). I have vroot.h, and this is the command I'm using:
gcc -lX11 -o simplesquares simplesquares.c
这是返回的错误:
These are the errors returned:
/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
什么是发生在这里,我怎么能解决这个问题?
What is happening here, and how can I fix it?
推荐答案
静态链接库,应在命令行的末尾。
Statically linked libraries should be at the end of the command line.
gcc -o simplesquares simplesquares.c -lX11
http://gcc.gnu.org/onlinedocs/gcc/Link -Options.html :
这使得其中的命令,你写这个选项是有所不同;该
连接器的搜索和处理库和目标文件的顺序
它们被指定。因此,foo.o的-lz文件bar.o'搜索库'Z'后
文件foo.o的,但bar.o.前如果bar.o指'Z'功能,
这些功能可能不会被加载。
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.
这篇关于GCC - 错误编译例子的xscreensaver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!