2015-09-08 105 views
2

查找圖書館我有這樣的CMake的腳本來查找庫:CMake的不能在Windows

# 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 :

$ 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. 
+1

準確的輸出會有幫助,所以我們可以準確地看到哪個'message()'調用確切地生成哪些輸出。另外,相當於'grep FANN CMakeCache.txt'會有幫助。 ---在不同的切線上,爲什麼CURRENT_SOURCE_DIR中有* .lib/* .dll文件? – DevSolar

+0

因爲我在窗戶上,所以我想把整件東西都放在一個包裏。我會重構我的層次結構,但它不應該一樣嗎? – manu34

+0

這只是一種「氣味」。 CMake的基本概念是,你根本不在源代碼樹中生成/生成任何東西(並讓CPack進行打包),所以我在那裏懷疑一些更基本的SNAFU。所以...你可以複製find_library()行並在副本上放置一條消息(「<...>」)?所以我們可以仔細檢查一下CMake究竟在尋找什麼,以排除關於調用時設置的變量的任何錯誤假設? – DevSolar

回答

1

OK ...它在那裏在衆目睽睽下所有的時間,但它採取的是最後message()輸出爲我真正意識到這一點。

set(_libraries doublefann fixedfann floatfann) 

和:

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

你看這個問題?你正在尋找錯誤的庫名稱。 (fanndoubledoublefann等)

+0

哈哈哈,不敢相信它...... – manu34

+0

@ manu34:我的一位前任老闆曾經說過,「一旦你找到了,每一個bug都是微不足道的。 「 ;-) – DevSolar