在Ubuntu 11.10中的链接器问题 [英] Linker problems in Ubuntu 11.10

查看:99
本文介绍了在Ubuntu 11.10中的链接器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在升级到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆