我已经完成了一个C程序,它将屏幕像素的RGB值(0-255)知道它的位置(x,y)。它适用于Linux,但是当我尝试在Visual Studio(Windows)中编译它时,由于库X11/Xlib.h,X11/Xutil.h,unistd.h不存在而崩溃。用于Windows的函数库“X11/Xlib.h”,“X11/Xutil.h”,“unistd.h”
这是代码:
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
void getimage(XColor c, Display* d, int* rgb, int x, int y) {
XImage* image;
image = XGetImage(d, RootWindow(d, DefaultScreen(d)),
x, y, 1, 1, AllPlanes, XYPixmap);
c.pixel = XGetPixel(image, 0, 0);
XFree(image);
XQueryColor(d, DefaultColormap(d, DefaultScreen(d)), &c);
rgb[0] = c.red/256;
rgb[1] = c.green/256;
rgb[2] = c.blue/256;
}
int main() {
int rgb[3], x, y;
XColor c;
Display* d = XOpenDisplay((char*)NULL);
getimage(c, d, rgb, x, y);
}
我怎样才能实现这个在Windows上运行?
这些是标题,而不是库。头文件是文本源文件,告诉编译器有什么可用的;除非你自己实现了库,否则它们是无用的。这些特定的头文件和库很大程度上是针对类Unix系统的。 Windows上有Unix仿真层,比如Cygwin。或者,您可以编写具有相同功能的代码,使用Windows提供的标题和库;结果将会非常不同。还有跨平台的库可以抽象出不同之处; wxWidgets就是一个例子。 –
这是编译器错误,不是崩溃。 – IInspectable
如果您的编译器**因丢失头文件而崩溃**,您应该在调试器中运行它并提交包含所有详细信息的错误报告。 – Olaf