autoconf

AC_CHECK_LIB with multiple dependencies


I want to use the oqs library in a project and I have to verify if the library is accesible. The project uses autoconf and I have to use AC_CHECK_LIB.

My first try was: AC_CHECK_LIB(oqs, OQS_randombytes, [LIBOQS_LIBS="-loqs"; ac_enable_pqc=yes], [ac_enable_pqc=no]), but this fails.

I was freaking out, so I've tried to "simulate" what AC_CHECK_LIB does. Created a simple C program which includes the oqs library and calls the OQS_randombytes function. Compiled it and got a lot of errors. I found out that the oqs library have some dependencies and I need to compile it this way:

gcc test.c -loqs -lssl -lcrypto.

So there are 2 dependencies. This way I created the following "thing" which I don't know if it's correct:

AC_CHECK_LIB([oqs -lssl -lcrypto], [OQS_randombytes], [LIBOQS_LIBS="-loqs -lssl -lcrypto"; ac_enable_pqc=yes], [ac_enable_pqc=no])

It really doesn't seems to be ok, but IT WORKS. So, is there a better way to do this?


Solution

  • It seems that the last argument from AC_CHECK_LIB is for dependencies:

    AC_CHECK_LIB (library, function, [action-if-found], [action-if-not-found], [other-libraries])

    In my case: AC_CHECK_LIB(oqs, OQS_randombytes, [LIBOQS_LIBS="-loqs"; ac_enable_pqc=yes], [ac_enable_pqc=no], [-lssl -lcrypto])