[CMake] CHECK_FUNCTION_EXISTS generates false positive for mlock(etc.)

Magnus Blåudd magnus.blaudd at oracle.com
Fri May 13 11:10:05 EDT 2011


Hi,

I'm examining a problem where cmake on Windows says it has detected a 
function(with CHECK_FUNCTION_EXISTS) although the compile has failed 
with a link error(according to the CMakeOutput.log).


The check is coded like:

INCLUDE(CheckFunctionExists)
<snip>
CHECK_FUNCTION_EXISTS(mlock HAVE_MLOCK)


And run on our build host like:

$> cmake .
<snip>
-- Looking for mlock
-- Looking for mlock - found

hmm, why did it find mlock on Windows?

$> opening CMakeFiles/CMakeOutput.log

Determining if the function mlock exists passed with the following output:
Change Dir: 
G:/pb2/build/sb_2-3326456-1305291464.82/mysql-5.1.56-ndb-7.0.25-win-x86_64/CMakeFiles/CMakeTmp

Run Build Command:F:\PROGRA~1\MICROS~1.0\Common7\IDE\devenv.com 
CMAKE_TRY_COMPILE.sln /build Debug /project cmTryCompileExec

Microsoft (R) Visual Studio Version 9.0.30729.1.
Copyright (C) Microsoft Corp. All rights reserved.
1>------ Build started: Project: cmTryCompileExec, Configuration: Debug 
x64 ------
1>Compiling...
1>Microsoft (R) C/C++ Optimizing Compiler Version 15.00.30729.01 for x64
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>cl /Od /D "WIN32" /D "_WINDOWS" /D "CHECK_FUNCTION_EXISTS=mlock" /D 
"_DEBUG" /D "CMAKE_INTDIR=\"Debug\"" /D "_MBCS" /FD /RTC1 /MDd 
/Fo"cmTryCompileExec.dir\Debug\\" 
/Fd"G:/pb2/build/sb_2-3326456-1305291464.82/mysql-5.1.56-ndb-7.0.25-win-x86_64/CMakeFiles/CMakeTmp/Debug/cmTryCompileExec.pdb" 
/W3 /c /Zi /TC   /Zm1000 /wd4800 /wd4805
1>   "C:\Program Files (x86)\CMake 
2.6\share\cmake-2.6\Modules\CheckFunctionExists.c"
1>CheckFunctionExists.c
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>CheckFunctionExists.obj : error LNK2019: unresolved external symbol 
mlock referenced in function main
1>G:\pb2\build\sb_2-3326456-1305291464.82\mysql-5.1.56-ndb-7.0.25-win-x86_64\CMakeFiles\CMakeTmp\Debug\cmTryCompileExec.exe 
: fatal error LNK1120: 1 unresolved externals
1>Build log was saved at 
"file://g:\pb2\build\sb_2-3326456-1305291464.82\mysql-5.1.56-ndb-7.0.25-win-x86_64\CMakeFiles\CMakeTmp\cmTryCompileExec.dir\Debug\BuildLog.htm"
1>cmTryCompileExec - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



How is this possible?

There are more false positive failures like this -  but this one was 
quite obvious (in my opinion).

Not sure which exact cmake version(2.6.?), sorry about that.

Best regards
Magnus Blåudd


More information about the CMake mailing list