Search code examples
cmakefile

How do I check the libc version from a makefile


How can I check the version of libc being used from a makefile?

I can do this from the terminal using ldd --version however I can't seem to get it handled from within the makefile so I can use it in a conditional statement.

I seem to be able to find methods referenced like gnu_get_libc_version which I think is run when autoconf builds the configure file however I'm not sure how to get the result and then be able to use it.

I've been trying things like this however none of it has been successful as of yet:

$glibc_version := $(shell ldd --version)
$(info  $glibc_version is [${glibc_version}]) // trying to print the result to make sure it's correct.

Solution

  • This syntax is wrong:

    $glibc_version := $(shell ldd --version)
    $(info  $glibc_version is [${glibc_version}])
    

    You don't include the $ when you define the variable. The $ is used to tell make that you are trying to reference a variable. The $g expands to the value of the variable g which is the empty string, so basically your makefile says:

    libc_version := $(shell ldd --version)
    $(info  libc_version is [${glibc_version}])
    

    Since you include the brackets in ${glibc_version} that refers to the variable named glibc_version, not libc_version which is what you set, so this will print:

    libc_version is []
    

    because that variable is empty. If you remove the incorrect uses of $ it will work:

    glibc_version := $(shell ldd --version)
    $(info glibc_version is [${glibc_version}])