Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cmake 检查\u库\u是否存在具有依赖项的库_Cmake - Fatal编程技术网

Cmake 检查\u库\u是否存在具有依赖项的库

Cmake 检查\u库\u是否存在具有依赖项的库,cmake,Cmake,我正在使用cmake构建我的c++项目,该项目使用位于我的“/usr/local/bin/”目录中的库。 CMakeList.txt中的相关部分如下: 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_

我正在使用cmake构建我的c++项目,该项目使用位于我的“/usr/local/bin/”目录中的库。 CMakeList.txt中的相关部分如下:

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测试程序的链接

我很高兴听到任何评论 多谢各位

Arne

根据,您可以在调用
检查库存在()之前,将
CMAKE_REQUIRED_库设置为链接测试所需的库列表。像这样:

set(CMAKE_REQUIRED_LIBRARIES m)
CHECK_LIBRARY_EXISTS(fann fann_get_errno "/usr/local/lib/" HAVE_FANN_LIB)

谢谢,这非常有帮助,并且修复了问题problem@AgnesSorr如果是这种情况,您应该将答案标记为已接受(通过单击绿色勾号)。这可能不可能立即完成,发布问题后会出现超时(我相信是15分钟)。而且,作为记录,在询问之前阅读文档通常是个好主意;-)就我个人而言,我使用一个定制的find_包调用()来处理这个问题,该调用还将确保找到Fann的所有依赖项。这方面的一个例子可以在(没有附属关系,没有写过或尝试过)找到,但是在linux环境中与数学相关的链接