[CMake] check_function_exists failing for gcc built-in functions?

Rolf Eike Beer eike at sf-mail.de
Wed Sep 19 12:57:37 EDT 2012


Jack Stalnaker wrote:
> Hi,
> 
> I'm having trouble with check_function_exists() when it comes to built-in
> functions in gcc. If I create just a simple C++ file with a call to sqrt()
> or pow() and have a CMakeLists.txt with the following lines,
> 
> include (CheckFunctionExists)
> check_function_exists(sqrt HAVE_SQRT)
> 
> cmake fails to find sqrt (or pow, log, exp, etc). In the sqrt case,
> CMakeError.log shows
> 
> /usr/share/cmake/Modules/CheckFunctionExists.c:3: warning: conflicting
> types for built-in function 'sqrt'
> Linking C executable cmTryCompileExec
> /usr/bin/cmake -E cmake_link_script
> CMakeFiles/cmTryCompileExec.dir/link.txt --verbose=1
> /usr/bin/gcc -DCHECK_FUNCTION_EXISTS=sqrt -fPIC
> CMakeFiles/cmTryCompileExec.dir/CheckFunctionExists.c.o -o cmTryCompileExec
> -rdynamic
> CMakeFiles/cmTryCompileExec.dir/CheckFunctionExists.c.o: In function
> 'main':
> CheckFunctionExists.c:(.text+0x15): undefined reference to 'sqrt'
> 
> What is the workaround for this, in the situation where the function is
> built in, but I want to test for it on other platforms?

set(CMAKE_REQUIRED_INCLUDES math.h)
set(CMAKE_REQUIRED_LIBRARIES m)

Eike
-- 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120919/ebe10f79/attachment.pgp>


More information about the CMake mailing list