문제

The following "Apple Mach-O Linker (Id) Error" occurs when I try to build a small C++ X11/Xlib program in XCode (Version 5).

Error:

The displayed linking error

Code:

#include <iostream>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <string>

using namespace std;

int main(int argc, const char * argv[])
{
    Display *d;
    Window w;
    XEvent e;
    string msg = "Hello, World!";
    int s;

    d = XOpenDisplay(NULL);
    if (d == NULL) {
        fprintf(stderr, "Cannot open display\n");
        exit(1);
    }

    s = DefaultScreen(d);
    w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1,
                            BlackPixel(d, s), WhitePixel(d, s));
    XSelectInput(d, w, ExposureMask | KeyPressMask);
    XMapWindow(d, w);

    while (1) {
        XNextEvent(d, &e);
        if (e.type == Expose) {
            XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
            XDrawString(d, w, DefaultGC(d, s), 10, 50, msg.c_str(), (int)msg.length());
        }
        if (e.type == KeyPress)
            break;
    }

    XCloseDisplay(d);
    return 0;
}

I've added /opt/X11/include and /opt/X11/lib to the Header Search Paths in Build Settings as suggested in another post This linker error is still appearing though.

I'm currently running OSX 10.8.5, and I've installed XQuartz.

Am I just missing a build setting, or is there potentially something I'm required to install which I've overlooked?

Any help would be greatly appreciated!

도움이 되었습니까?

해결책

It turned out I was receiving these errors because I wasn't properly setting the flags within XCode.

To solve this issue, go to the Build Settings of your project and add to "Other Linker Flags" the flags:

-I/usr/X11R6/include -L/usr/X11R6/lib -lX11

다른 팁

It simply means that you have not linked the library. Please see the build log and see if the library is being linked.

If not, then link it. If it is still linked, then it may not have function.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top