如何在C ++中确定RHEL的不同版本 [英] How to determine different versions of RHEL in c++

查看:63
本文介绍了如何在C ++中确定RHEL的不同版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要基于RedhatLinux的不同版本在c ++程序中进行条件编译,例如对于RHEL 5.5,我需要定义一些宏,对于RHEl 6.1,这些宏将具有不同的值.
喜欢,

Hi,

I need to do conditional compilation in a c++ program based on the different version of RedhatLinux for example for RHEL 5.5 I need to define some macros and for RHEl 6.1 these macros will have different values.
Like,

#ifdef LINUX
    #define MY_STRING "abc"
#else
    #define MY_STRING "def"
#endif



但是"#ifdef LINUX"适用于所有版本的RHEL.

因此,任何机构都可以帮助我如何完成此任务.

我对RHEL 6.1和RHEL 5.5的要求是这样的,我需要声明一些预处理器指令,例如
因此请plz帮助确定不同版本的RHEL.

谢谢,
开发方案



but "#ifdef LINUX" is for all the versions of RHEL.

So can any body plz help me how to get this done.

My requirement is as such for RHEL 6.1 and RHEL 5.5 I need to declare some preprocessor directives like
So plz help in determining different versions of RHEL.

Thanks,
Dev.

推荐答案

最简单的方法是在buid时在您的gcc调用或Makefile中添加动态定义.
The easiest way would be to add a dynamic definition at buid time, either in your gcc call or in your Makefile.


试图弄清楚Linux上的版本真是太可惜了.所以甚至不要尝试.真的,这不值得.我知道,这是个废话,你应该怎么做?麻烦的是Linux系统,即使来自同一个发行版CD也可能彼此完全不同.不同版本的库,甚至不同的库也将停止.

因此,我要做的就是从平台上确定您需要哪些功能,并检查它们是否存在.功能是您希望代码在各种平台上实现的功能-安装的库,安装的库中的函数或系统调用都是可以成为功能的东西.

要么:

-使用AC_CHECK_FUNC ,以便在为特定平台配置代码时测试特定功能是否存在

-编写一些小程序来测试所需功能的行为,并使用AC_RUN_IFELSE 设置预处理器定义甚至宏本身.

现在您可能正坐在那里,呵呵,他在想什么?"如果您在谈论自动工具,这是一种为UNIXy风格系统上运行的程序生成配置脚本的好方法.它们使您能够编写几个相对简单的文本文件,它们几乎可以在任何系统上为您生成make文件.酷还是什么?

它们可能是个麻烦的工具,但是如果您对在Linux上进行编程很认真,请查看山羊皮书 [ ^ ]描述了如何使用自动工具.值得花点时间来学习如何使用它们.这篇 Wikipedia文章 [
It''s a real bummer trying to work out versions on Linux. So don''t even try. Really, it ain''t worth it. I know, what a crap answer, what are you supposed to do? The trouble is Linux systems, even from the same distro CD can be completely different from each other. Different versions of libraries, even different libraries full stop.

So what I''d do is work out what features you need from the platform and check to see if they exist. A feature is something you want the code to do that''s different on various platforms - an installed library, function in an installed library or a system call are all things that can be features.

Either:

- Use AC_CHECK_FUNC so you can test that a particular function is there when you configure your code for a particular platform

- write little programs to test the behaviour of the functions you want and use AC_RUN_IFELSE to set preprocessor defines or even the macros themselves.

Now you might be sitting there going "Huh, what''s he wittering on about?" If you are I''m talking about autotools, a good way of generating configure scripts for programs that run on UNIXy style systems. They enable you to write a couple of relatively simple text files that''ll generate the make file for you on just about any system. Cool or what?

They can be a bugger to use but if you''re serious about programming on Linux then have a look at the Goat Book[^] which describes how to use the autotools. It''s worth spending a while to learn how to use them. This Wikipedia article[^] gives a good overview of how the tools fit together.


这篇关于如何在C ++中确定RHEL的不同版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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