GLib是否可以检测操作系统? [英] Is OS detection possible with GLib?

查看:95
本文介绍了GLib是否可以检测操作系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以确定我的Vala应用程序在哪个平台(GNU / Linux,Win32,OS X)上运行?

解决方案

由于Vala是一种编译语言(相对于中间语言或解释语言),因此您可以使用自己喜欢的构建工具和使用条件编译



类似的东西:



< pre class = lang-cs prettyprint-override> #if WINDOWS
消息(在Windows上运行);
#elif OSX
消息(在OS X上运行);
#elif LINUX
消息(在GNU / Linux上运行);
#elif POSIX
消息(在其他POSIX系统上运行);
#else
消息(在未知操作系统上运行);
#endif

构建工具必须通过 -D LINUX 等到编译器。



我会小心一点,只能这样做,因为这会适得其反。通常最好使用已经为您处理差异的跨平台库。



BTW:另请参见如何在C ++中完成


Is it possible to determine on which platform (GNU/Linux, Win32, OS X) my Vala app is running?

解决方案

As Vala is a compiled language (as opposed to intermediate or interpreted) you can determine the platform using your favorite build tool and use conditional compilation.

Something like:

#if WINDOWS
    message ("Running on Windows");
#elif OSX
    message ("Running on OS X");
#elif LINUX
    message ("Running on GNU/Linux");
#elif POSIX
    message ("Running on other POSIX system");
#else
    message ("Running on unknown OS");
#endif

The build tool would have to pass -D LINUX, etc to the compiler.

I would be careful and only do something like this as a last resort, because it can backfire. Usually it's better to use cross platform libraries that already handle the differences for you.

BTW: See also how this is done in C++.

这篇关于GLib是否可以检测操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆