CMake无法在Windows上找到库

时间:2015-09-08 13:20:24

标签: 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" 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
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.

这是我的grep FANN CMakeCache.txt:

 list.sort{ it.dueDate }

1 个答案:

答案 0 :(得分:1)

好的......它一直在那里,但我最后message()输出才真正意识到它。

set( _libraries doublefann fixedfann floatfann )

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

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