CHECK_LIBRARY_EXISTS library with dependencies <p>I'm using cmake to build my c++-project that uses a library that is located in my "/usr/local/bin/" directory. The relevant part in the CMakeList.txt reads:</p> <pre><code>CHECK_INCLUDE_FILES("/usr/local/include/fann.h" HAVE_FANN_HEADER) CHECK_LIBRARY_EXISTS(fann fann_get_errno "/usr/local/lib/" HAVE_FANN_LIB) if(${HAVE_FANN_HEADER} AND ${HAVE_FANN_LIB}) </code></pre> <p>the header is found without a problem the while library is not. Looking into the CMakeError.txt shows:</p> <pre><code>`/usr/bin/cc -DCHECK_FUNCTION_EXISTS=fann_get_errno CMakeFiles/cmTryCompileExec2973046031.dir/CheckFunctionExists.c.o -o cmTryCompileExec2973046031 -L/usr/local/lib -rdynamic -lfann -Wl,-rpath,/usr/local/lib /usr/local/lib/libfann.so: undefined reference to 'sin' /usr/local/lib/libfann.so: undefined reference to 'exp' /usr/local/lib/libfann.so: undefined reference to 'cos' /usr/local/lib/libfann.so: undefined reference to 'log' /usr/local/lib/libfann.so: undefined reference to 'pow' /usr/local/lib/libfann.so: undefined reference to 'sqrt' /usr/local/lib/libfann.so: undefined reference to 'floor'` </code></pre> <p>in the subsequent if-statement the second variable is therefore undefined.</p> <p>I suspect that this is because the test program is not linked with the standard math library. However in my main program the libm.so will be linked.</p> <p>How do I fix the linking of the cmake test program?</p> <p>I would be happy about any comments Thank you</p> <p>Arne</p>