简体   繁体   English

如何使用#ifdef检查Xlib是否被使用?

[英]How to check if Xlib is used using #ifdef?

For example you can check if Windows is used by checking if "WIN32" macro is defined. 例如,可以通过检查是否定义了“ WIN32”宏来检查是否使用Windows。 And i would like to get the same behaviour but to check if Xlib is used. 我想得到相同的行为,但要检查是否使用了Xlib。 But i don't know what Xlib defines to know it's defined. 但是我不知道Xlib定义什么才能知道它的定义。 If you don't know what i mean here is an example: 如果您不知道我的意思,这是一个例子:

#ifdef WIN32 //Check if WIN32 is defined
//Do something
#endif

And i would like to change this in a way that it does something when Xlib used. 我想以一种使用Xlib时会执行某些操作的方式来更改它。

I'm sorry if there are some grammatical errors but i'm not a native english speaker. 对不起,如果有一些语法错误,但我不是英语母语人士。

The macro WIN32 is only defined, if you included #include <windows.h> before or set the macro in your compiler flags ( -DWIN32 ). 仅当您在#include <windows.h>之前包含#include <windows.h>或在编译器标志( -DWIN32 )中设置该宏时,才定义宏WIN32 For Xlib you could use the macro X_PROTOCOL very similar if you included #include <X11/Xh> before. 对于Xlib,如果之前包含#include <X11/Xh> ,则可以使用非常相似的宏X_PROTOCOL

#ifdef X_PROTOCOL //Check if X_PROTOCOL is defined
//Do something
#endif

Another way would be to use _XLIB_H_ if you included #include <X11/Xlib.h> before, but I wouldn't because identifiers beginning with an underscore are reserved to the implementation and there is no guarantee that this identifiers won't change. 另一种方法是,如果之前包含#include <X11/Xlib.h> ,则使用_XLIB_H_ ,但我不#include <X11/Xlib.h> ,因为以下划线开头的标识符保留给实现,并且不能保证此标识符不会更改。

you can check if Windows is used by checking if "WIN32" macro is defined 您可以通过检查是否定义了“ WIN32”宏来检查是否使用了Windows

The WIN32 macro is defined by default by compilers that target Windows OS. 默认情况下, WIN32宏是由WIN32 Windows OS的编译器定义的。 Its purpose is to let the program detect Windows OS API, not necessarily any graphic subsystem. 其目的是让程序检测Windows OS API,而不必检测任何图形子系统。

X11 is not and OS. X11不是和OS。 It's optional userland software that installs and runs under many operating systems, including Windows. 它是可选的 userland软件,可以在许多操作系统(包括Windows)上安装和运行。 When compiling an X11 programs for Windows, WIN32 will be defined, just like for any other Windows program. 当为Windows编译X11程序时,将定义WIN32,就像其他任何Windows程序一样。

No compiler defines anything by default on a system where X11 is installed. 默认情况下,没有编译器在安装X11的系统上定义任何内容。

If you want to detect X11 at build time, your best bet is probably a meta-build tool like GNU autotools or CMake. 如果要在构建时检测X11,最好的选择可能是元构建工具,例如GNU autotools或CMake。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM