gpt4 book ai didi

c++ - 确定 linux 发行版的宏

转载 作者:太空狗 更新时间:2023-10-29 12:01:52 25 4
gpt4 key购买 nike

我想添加一个基于 Linux 发行版的宏,例如,Ubuntu 15 与 Ubuntu 14LTS。因此,在 __linux 的 ifdef 中,我将执行检查:

#ifdef __linux
// find version
#endif

有没有聪明的方法来做到这一点?感谢您的任何想法

最佳答案

我只是在 C++ 之外编写一些东西来为您定义宏。我在 Boost.Predef 中没有看到任何内容它为您提供的不仅仅是 Linux。像这样的东西:

linux_defines() {
if -f /etc/redhat-release; then
awk '{
printf("-D__rhel_ver__=%d\n",$7 * 100)
}' /etc/redhat-release
elif -f /etc/lsb-release; then
awk -F= '$1 == "DISTRIB_RELEASE"{
printf("-D__ubuntu_ver__=%d\n",$2 * 100)
}' /etc/lsb-release
elif ...
...
fi
}

并在您的 makefile 中调用它以扩展您的 CPPFLAGS(或 CXXFLAGS 或...)

关于c++ - 确定 linux 发行版的宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32274200/

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