Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linker problems in Ubuntu 11.10

Tags:

gcc

ubuntu

linker

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.

like image 273
cyberguijarro Avatar asked Jan 24 '12 09:01

cyberguijarro


1 Answers

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.

like image 111
Employed Russian Avatar answered Sep 30 '22 05:09

Employed Russian