Answer the question
In order to leave comments, you need to log in
Weirdness with CHECK_C_SOURCE_COMPILES macro from CMake
I am translating the project, or rather part of it, to cmake. To check for the presence of a function, previously used
AC_MSG_CHECKING(for function clock_gettime in time.h)
AC_TRY_LINK([
#include <time.h>
],
[struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
],
AC_DEFINE(HAVE_TIME_CLOCK_GETTIME,1,[Define to 1 if function 'clock_gettime' exists.])
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
On my host, checking shows the presence of this feature. INCLUDE (CheckFunctionExists)
CHECK_FUNCTION_EXISTS(clock_gettime HAVE_TIME_CLOCK_GETTIME)
andINCLUDE (CheckCSourceCompiles)
CHECK_C_SOURCE_COMPILES("#include <time.h>
int main(int argc, char * argv[]) {
struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp))
}" HAVE_TIME_CLOCK_GETTIME)
In both cases, failure. Please tell me what am I doing wrong?
Answer the question
In order to leave comments, you need to log in
According to the documentation, the clock_gettime function requires linking with the rt library (Link with -lrt), so cmake cannot link the test code.
According to the cmake documentation, you can use the CMAKE_REQUIRED_LIBRARIES variable to ensure that the above functions include the required library when linking.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question