manu34
manu34

Reputation: 75

CMake cannot find library on Windows

I Have this CMake script to find a library:

#  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()

The script is called FindFANN.cmake and it is called by my main script with the find_package() command. Now I have also printed the directories "${CMAKE_CURRENT_SOURCE_DIR}/FANN/lib" and "${CMAKE_CURRENT_SOURCE_DIR}/FANN/include" and they are right. However the libraries are not found and I cannot understand why. In "${CMAKE_CURRENT_SOURCE_DIR}/FANN/lib" I have:

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

While in "${CMAKE_CURRENT_SOURCE_DIR}/FANN/include" I have fann.h among the others headers.

I know this is not the best portable script, but for now I just need it to work...

This is the exact output

$ 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".

Here is my 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.

Upvotes: 2

Views: 2644

Answers (1)

DevSolar
DevSolar

Reputation: 70213

OK... it was there in plain sight all the time but it took that last message() output for me to actually realize it.

set( _libraries doublefann fixedfann floatfann )

And:

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

You see the problem? You're looking for the wrong library names. (fanndouble versus doublefann etc.)

Upvotes: 2

Related Questions