【发布时间】:2013-12-06 13:47:21
【问题描述】:
当我尝试在 XCode(版本 5)中构建一个小型 C++ X11/Xlib 程序时,出现以下“Apple Mach-O Linker (Id) Error”。
错误:
代码:
#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;
}
我已按照another post 此链接器中的建议将 /opt/X11/include 和 /opt/X11/lib 添加到构建设置中的标头搜索路径中但是仍然出现错误。
我目前运行的是 OSX 10.8.5,并且我已经安装了 XQuartz。
我只是缺少构建设置,还是可能需要安装一些我忽略的东西?
任何帮助将不胜感激!
【问题讨论】: