Hi,

it is an interesting problem. If you tell the gcc to use the math library, it works. The interesting thing is the way of testing.

The cmake macro simply declares a function foo with the signature
    char foo();
and call this one without arguments. If you tell cmake to link against the math library, it works.

But, if you simply call sqrt(5.0) the library is ommitted (I think the gcc optimizes the code?)

So, if you always know the math library for the specific platform, you should use it.

Hth,

Andreas

Am 19.09.2012 17:08, schrieb Jack Stalnaker:
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?

Thanks
-- Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to