gpt4 book ai didi

c - C 中 x11 的链接问题

转载 作者:行者123 更新时间:2023-11-30 15:56:23 26 4
gpt4 key购买 nike

我正在尝试使用 X11 构建 getPixelColor 函数:

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

void getPixelColor (Display *d, int x, int y, XColor *color)
{
XImage *image;
image = XGetImage (d, RootWindow (d, DefaultScreen (d)), x, y, 1, 1, AllPlanes,
XYPixmap);
color->pixel = XGetPixel (image, 0, 0);
XFree (image);
XQueryColor (d, DefaultColormap(d, DefaultScreen (d)), color);
}

int main(int argc, const char * argv[])
{
return 0;
}

但是我收到以下错误,似乎是在链接期间:

Undefined symbols for architecture x86_64:
"_XGetImage", referenced from:
_getPixelColor in main.o
"_XFree", referenced from:
_getPixelColor in main.o
"_XQueryColor", referenced from:
_getPixelColor in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

知道问题出在哪里吗?我的印象是 X11 不是一个我在项目中作为库链接的框架 - 只要我提供正确的 header ,那么我应该没问题......这是不正确的吗?

最佳答案

是的,您需要链接 xlib。这对我有用:

09:25 tmp $ gcc test.cpp /usr/X11/lib/libX11.dylib 
09:26 tmp $ ./a.out
09:26 tmp $

或使用 L 开关和库路径:

09:26 tmp $ gcc test.cpp -L/usr/X11/lib -lX11
09:30 tmp $ otool -L a.out
a.out:
/usr/X11/lib/libX11.6.dylib (compatibility version 10.0.0, current version 10.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

关于c - C 中 x11 的链接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11302318/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com