I want to add a check for a minimal version of a library that I need for my project at configure time.
The library itself stores its version in a struct library_name_version_struct, such that I could obtain the library version using the following code:
#include "library_name.h"
void main(void){
printf("%s\n", library_name_version_struct.version);
}
which would give me the output
libraryMAJOR.MINOR.MICRO
I thought of trying to get autoconf to run that minimal code, capture the output, and then (at least as a start) just stupidly check whether the output string is in a list of permissible output strings that I specify. Something along the lines of
AC_MAGIC_COMMAND_THAT_I_DONT_KNOW( [[#include "library_name.h"],
[printf("%s\n", library_name_version_struct.version);]],
[STORE_OUTPUT_IN_THIS_VARIABLE],
[Oh no something went really wrong])
case STORE_OUTPUT_IN_THIS_VARIABLE in
library_name1.0.0 | library_name1.1.0 | (etc...) | library_name3.1.0)
# we good
;;
*)
AC_MSG_ERROR([STORE_OUTPUT_IN_THIS_VARIABLE is not a permitted version])
;;
esac
Any other or better way of achieving this would also be very much appreciated. I just want to get this to work.
The Autoconf macro you are looking for is
AC_RUN_IFELSE.However, there are at least two problems with using
AC_RUN_IFELSEto check for the runtime value oflibrary_name_version_struct.version:AC_RUN_IFELSEcannot detect the library version when cross compiling.The library version present at the time your binary program is built can differ from the library version the compiled program eventually runs with.
I would try to look for a different mechanism to check for the library version. Check for some minimum ABI version for compilation (e.g. with
PKG_CHECK_MODULESif the library in question supports that), and then maybe an actual runtime check for inside the compiled program.More details about or a concrete pointer to the library in question might enable a more useful answers.