在Ubuntu 11.10中的链接器问题 [英] Linker problems in Ubuntu 11.10
问题描述
#include< X11 / Xlib.h>
int main(){
Display * display = XOpenDisplay(:0.0);
XCloseDisplay(display);
返回0;
使用以下内容进行编译:
g ++ -lX11 test.cpp
或
p> g ++ -c -o test.o test.cpp
g ++ -lX11 -o test test.o
导致失败发生:
/tmp/ccBAOpzy.o:在函数`main'中:
test.cpp :( .text + 0x11):未定义的对'XOpenDisplay'的引用
test.cpp :( .text + 0x21):未定义引用'XCloseDisplay'
任何想法?我发现11.10中有些链接器的内容发生了变化:
https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition
但是仍然没有解释这些问题。
g ++ -lX11 -o test test.o
p>
上述命令不正确。试试这个:
g ++ test.o -lX11
解释订单为何重要的原因此处。
另外,您不应该在UNIX上调用可执行文件 test
。
after upgrading to Ubuntu 11.10, I've found that many of my old and current developments can't be compiled anymore. I've reduced the problem to a simple example:
#include <X11/Xlib.h>
int main() {
Display* display = XOpenDisplay(":0.0");
XCloseDisplay(display);
return 0;
}
Compiling it using:
g++ -lX11 test.cpp
or
g++ -c -o test.o test.cpp
g++ -lX11 -o test test.o
Causes a failure to happen:
/tmp/ccBAOpzy.o: In function `main':
test.cpp:(.text+0x11): undefined reference to `XOpenDisplay'
test.cpp:(.text+0x21): undefined reference to `XCloseDisplay'
Any ideas? I've found that some linker stuff has changed in 11.10:
https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition
But still doesn't explain these problems.
g++ -lX11 -o test test.o
Above command is incorrect. Try this instead:
g++ test.o -lX11
Explanation of why the order matters here.
Also, you should never call your executables test
on UNIX.
这篇关于在Ubuntu 11.10中的链接器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!