windows - CMake 在 Windows 上找不到库

标签 windows cmake

我有这个 CMake 脚本来查找库:

#  FANN_FOUND - system has fann
#  FANN_INCLUDE_DIRS - the fann include directory
#  FANN_LIBRARIES - Link these to use fann
#  FANN_DEFINITIONS - Compiler switches required for using fann
if(FANN_LIBRARIES AND FANN_INCLUDE_DIRS)
    set(FANN_FOUND TRUE)
else()

    find_path(FANN_INCLUDE_DIR NAMES fann.h PATHS ${CMAKE_CURRENT_SOURCE_DIR}/FANN/include)
    set( _libraries doublefann fixedfann floatfann )

    foreach( _lib ${_libraries} )
        string( TOUPPER ${_lib} _name )
        find_library(${_name}_LIBRARY NAMES ${_lib} PATHS "${CMAKE_CURRENT_SOURCE_DIR}/FANN/lib")
    endforeach()

    set(FANN_INCLUDE_DIRS ${FANN_INCLUDE_DIR})
    message("${FANN_INCLUDE_DIR}")
    set(FANN_LIBRARIES ${FANN_LIBRARIES} ${DOUBLEFANN_LIBRARY}
    ${FIXEDFANN_LIBRARY} ${FLOATFANN_LIBRARY} )

    if( UNIX )
        set( FANN_LIBRARIES ${FANN_LIBRARIES} m )
    endif()

    if(FANN_INCLUDE_DIRS AND FANN_LIBRARIES)
        set(FANN_FOUND TRUE)
    endif()

    if(FANN_FOUND)
        if(NOT FANN_FIND_QUIETLY)
            message(STATUS "Found FANN:")
            message(STATUS "FANN_INCLUDE_DIRS: ${FANN_INCLUDE_DIRS}")
            message(STATUS "FANN_LIBRARIES: ${FANN_LIBRARIES}")
        endif()
     else()
         if(FANN_FIND_REQUIRED)
             message(FATAL_ERROR "Could not find FANN")
         endif()
     endif()

mark_as_advanced(FANN_INCLUDE_DIRS FANN_LIBRARIES)
endif()

该脚本名为 FindFANN.cmake,由我的主脚本使用 find_package() 命令调用。现在我还打印了目录 "${CMAKE_CURRENT_SOURCE_DIR}/FANN/lib""${CMAKE_CURRENT_SOURCE_DIR}/FANN/include" 并且它们是正确的。 但是没有找到这些库,我不明白为什么。 在 “${CMAKE_CURRENT_SOURCE_DIR}/FANN/lib” 中我有:

fanndouble.dll
fanndouble.lib
fannfixed.dll
fannfixed.lib
fannfloat.dll
fannfloat.lib

"${CMAKE_CURRENT_SOURCE_DIR}/FANN/include" 中,我在其他 header 中包含 fann.h

我知道这不是最好的可移植脚本,但现在我只需要它工作......

这是确切的输出

$ cmake . -G "CodeBlocks - Unix Makefiles" 
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- Check for working C compiler: c:/MinGW/bin/cc.exe
-- Check for working C compiler: c:/MinGW/bin/cc.exe
-- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done 
-- Check for working CXX compiler: c:/MinGW/bin/c++.exe 
-- Check for working CXX compiler: c:/MinGW/bin/c++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done 
CMake Error at cmake/Modules/FindFANN.cmake:91 (message): 
    Could not find FANN
Call Stack (most recent call first):
    CMakeLists.txt:30 (find_package)

-- Configuring incomplete, errors occurred!
See also "C:/Users/Manuele/Documents/TicTacToe/CMakeFiles/CMakeOutput.log".

这是我的 grep FANN CMakeCache.txt:

$ grep FANN CMakeCache.txt
DOUBLEFANN.LIB_LIBRARY:FILEPATH=DOUBLEFANN.LIB_LIBRARY-NOTFOUND
DOUBLEFANN_LIBRARY:FILEPATH=DOUBLEFANN_LIBRARY-NOTFOUND
FANN_DIR:UNINITIALIZED=C:/Users/Manuele/Documents/TicTacToe/FANN/
FANN_INCLUDE_DIR:PATH=c:/Users/Manuele/Documents/TicTacToe/FANN/include
FIXEDFANN.LIB_LIBRARY:FILEPATH=FIXEDFANN.LIB_LIBRARY-NOTFOUND
FIXEDFANN_LIBRARY:FILEPATH=FIXEDFANN_LIBRARY-NOTFOUND
FLOATFANN.LIB_LIBRARY:FILEPATH=FLOATFANN.LIB_LIBRARY-NOTFOUND
FLOATFANN_LIBRARY:FILEPATH=FLOATFANN_LIBRARY-NOTFOUND.

最佳答案

好吧...它一直都在眼前,但直到最后一个 message() 输出我才真正意识到它。

set( _libraries doublefann fixedfann floatfann )

还有:

fanndouble.dll
fanndouble.lib
fannfixed.dll
fannfixed.lib
fannfloat.dll
fannfloat.lib

你看到问题了吗?您正在寻找错误的库名称。 (fanndoubledoublefann 等)

关于windows - CMake 在 Windows 上找不到库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32458965/

相关文章:

c++ - CMAKE 链接器没有找到库;但是使用 find_library 找到了库

configuration - 在不包装脚本的情况下让 CMake 从源代码中构建

c++ - 如何使用 cmake 将文件夹路径包含到 C/C++ 程序中

javascript - Iron-router(最新)在 Windows 7 x64 (Meteor 0.8.3) 上的安装问题

css - Windows Phone 8 视口(viewport)问题

.net - 使用 Visual Basic 在 Windows 窗体中嵌入 DOS 控制台

iphone - Windows 上的 DragonFireSDK 和 iPhone 开发

python - 在 Windows 上使用 PyCharm 的 matplotlib 不会绘制图形,没有错误

c++ - 为什么 CMake 生成不带 CMAKE_CXX_FLAGS 的 Makefile?

gcc - CMake 库链接顺序