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

Rolf Eike Beer eike at sf-mail.de
Wed Sep 19 13:25:58 EDT 2012


Andreas Naumann wrote:
> 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?)

As it also does with e.g. strlen("something"). Functions that are marked to 
return the same value if the same value is passed in and which are used with a 
constant input are calculated during compilation and the result is used in the 
binary. So if you write something like:

if (sqrt(strlen("foobar")) > 4)
  return 1;
else
  return 0;

I'm rather sure the code generated by gcc (if optimizations are turned on) 
will be just "return 0".

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/ae1e0eac/attachment.pgp>


More information about the CMake mailing list