0

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

3
  • How is the title related to the error given in the question? I'd say you have to install the X11 headers (according to your title) and the X11 library (according to your question). This might help you: support.apple.com/kb/ht5293 If you use macports you can install xorg-libX11
    – usr1234567
    Apr 3, 2014 at 5:30
  • what do you have on LD_LIBRARY_PATH? Apr 3, 2014 at 8:25
  • I have Xlib.h in /opt/X11/include
    – Jing
    Apr 3, 2014 at 14:11

2 Answers 2

1

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
0

Try

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.