C/C++ 获取当前程序编译依赖的GLIBC版本 ON LINUX/GUN

获取代码:

#include <gnu/libc-version.h>
#include <stdio.h>
#include <unistd.h>

int main() {
    // method 1, use macro
    printf("%d.%d\n", __GLIBC__, __GLIBC_MINOR__);

    // method 2, use gnu_get_libc_version 
    puts(gnu_get_libc_version());

    // method 3, use confstr function
    char version[30] = {0};
    confstr(_CS_GNU_LIBC_VERSION, version, 30);
    puts(version);

    return 0;
}

输出结果:

$ gcc main.cpp -o main
$ ./main
2.30
2.30
glibc 2.30

猜你喜欢

转载自blog.csdn.net/liulilittle/article/details/142031501