Jing
Jing

Reputation: 11

fatal error: 'X11/Xlib.h' file not found

I have installed XQuartz. I compiled using g++:

g++ -o -lX11 -I/opt/X11/include window2.cc

Error

Undefined symbols for architecture x86_64:

"_XCreateWindow", referenced from:
  _main in window2-dXb9bZ.o
 "_XFlush", referenced from:
  _main in window2-dXb9bZ.o
"_XMapWindow", referenced from:
  _main in window2-dXb9bZ.o
"_XOpenDisplay", referenced from:
  _main in window2-dXb9bZ.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If i compile like this:

g++ window2.cc -o window -lX11 -I/opt/X11/include

Error

ld: library not found for -lX11
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Im sure Xlib.h is in /opt/X11/include

Code:

#include <X11/Xlib.h>
#include <unistd.h>

int main()
  {
  // Open a display.
  Display *d = XOpenDisplay(0);

 if ( d )
{
  // Create the window
  Window w = XCreateWindow(d, DefaultRootWindow(d), 0, 0, 200,
                           100, 0, CopyFromParent, CopyFromParent,
                           CopyFromParent, 0, 0);

  // Show the window
  XMapWindow(d, w);
  XFlush(d);

  // Sleep long enough to see the window.
  sleep(10);
}
 return 0;
 }

How do I solve this problem ? Thanks in advance

Upvotes: 0

Views: 7582

Answers (2)

Jing
Jing

Reputation: 11

Problem resolved. In case anyone who's interested: You have to compile like this:

g++ -o window window.cc -I/usr/X11R6/include -L/usr/X11R6/lib -lX11

Upvotes: 1

lhf
lhf

Reputation: 72412

Try

cc -I /opt/X11/include/ test.c -L /opt/X11/lib -lX11

Upvotes: 0

Related Questions