我已经安装了XQuartz。 我用g ++编译:
g++ -o -lX11 -I/opt/X11/include window2.cc
错误
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)
如果我这样编译:
g++ window2.cc -o window -lX11 -I/opt/X11/include
错误
ld: library not found for -lX11
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我确定Xlib.h在/ opt / X11 / include
中代码:
#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;
}
我该如何解决这个问题?提前致谢
答案 0 :(得分:1)
问题已解决。万一有兴趣的人: 你必须像这样编译:
g++ -o window window.cc -I/usr/X11R6/include -L/usr/X11R6/lib -lX11
答案 1 :(得分:0)
尝试
cc -I /opt/X11/include/ test.c -L /opt/X11/lib -lX11