我正在使用cmake来构建我的C++ - 使用位于我的“/ usr/local/bin /”目录中的库的项目。 在CMakeList.txt有关部分的内容:CHECK_LIBRARY_EXISTS库与依赖关系
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})
页眉发现没有问题的,而图书馆是没有的。查看CMakeError.txt显示:
`/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'`
在随后的if语句中,第二个变量因此未定义。
我怀疑这是因为测试程序没有与标准的数学库链接。但是在我的主程序中,libm.so将被链接。
如何解决cmake测试程序的链接问题?
我会很高兴有任何意见 谢谢
阿恩
就个人而言,我处理这个使用一个自定义find_package调用(http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries),也将确保范文芳的所有依赖被发现。一个例子可以在https://github.com/jrdi/fann-box/blob/master/cmake/FindFANN.cmake找到(没有从属关系,没有写或尝试它),但在Linux的数学链接enviroment – IdeaHat 2014-12-03 14:24:11