2010-08-21 28 views
0

En fait, je crée un script CMake pour localiser la bibliothèque DevIL à l'aide de MSYS/MinGW sur la plate-forme win32. J'ai étendre l'origine de script FindDevIL CMake à considérer la racine MinGW lorsque vous essayez de trouver DevIL:Problème sur l'utilisation de CMAKE avec des fichiers DLL de liaison MSYS/MinGW à l'aide de la bibliothèque d'images DevIL

project (DevILTest) 
cmake_minimum_required(VERSION 2.6) 

FIND_PACKAGE(OpenGL) 
IF(OPENGL_FOUND) 
    MESSAGE(STATUS "OpenGL render API found.") 
    MESSAGE(STATUS "Detected OpenGL path is : ${OPENGL_LIBRARIES}") 
ENDIF(OPENGL_FOUND) 

#Determine DevIL specific header file   
FIND_PATH(IL_INCLUDE_DIR il.h 
     PATH_SUFFIXES include/IL 
     PATHS c:/mingw 
     DOC "The path the the directory that contains il.h" 
) 
MESSAGE("Found DevIL includes at: ${IL_INCLUDE_DIR}") 

#Determine DevIL library 
FIND_LIBRARY(IL_LIBRARY NAMES DEVIL 
    PATH_SUFFIXES lib 
    PATHS c:/mingw 
    DOC "The file that corresponds to the base il library." 
) 
MESSAGE("Found DevIL library at: ${IL_LIBRARY}") 

SET (Sources 
winmain.cpp 
) 

SET(CMAKE_VERBOSE_MAKEFILE ON) 
SET(IL_INCLUDE_DIR /c/binrev/development/mingw/include) 

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} 
      ${CMAKE_CURRENT_SOURCE_DIR}/src 
      ${IL_INCLUDE_DIR} 
      /usr/include 
      /usr/local/include    
) 

add_executable (DevILTest ${Sources}) 
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}) 
TARGET_LINK_LIBRARIES(DevILTest ${OPENGL_LIBRARIES} ${IL_LIBRARY}) 

Les fichiers du DIABLE sont placés dans un sous-dossier bin, les fichiers DevIL.lib et DevIL.a dans le répertoire lib sous-dossier de MinGW root (c:/mingw). J'utilise find_library() pour vérifier si une bibliothèque existe.

-- OpenGL render API found. 
-- Detected OpenGL path is : glu32;opengl32 
-- Found DevIL includes at: C:/mingw/include/IL 
-- Found DevIL library at: C:/mingw/bin/DevIL.dll 

Find_libary() retourne AllWays le chemin vers les fichiers dll - mais je ne peux pas relier cette bibliothèque en utilisant MinGW:

Linking CXX executable DevILTest.exe 
/C/binrev/development/mingw/bin/g++.exe  "CMakeFiles/DevILTest.dir /winmain.cpp.obj" -o DevILTest.exe -Wl,--out-implib,libDevILTest.dll.a -Wl,--ma 
32 -lopengl32 DevIL.dll -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 
CMakeFiles/DevILTest.dir/winmain.cpp.obj:winmain.cpp:(.text+0xcc8): undefined reference to `[email protected]' 
CMakeFiles/DevILTest.dir/winmain.cpp.obj:winmain.cpp:(.text+0xce0): undefined reference to `[email protected]' 
CMakeFiles/DevILTest.dir/winmain.cpp.obj:winmain.cpp:(.text+0xcf9): undefined reference to `[email protected]' 

Si je supprime les fichiers dll et exécutez le CMake skript la bibliothèque DevIL.lib est localisée correctement et je vais sans échec de l'éditeur de liens:

-- Detected OpenGL path is : glu32;opengl32 
-- Found DevIL includes at: C:/mingw/include/IL 
-- Found DevIL library at: C:/mingw/lib/DevIL.lib 

Mais quand dans ce cas, les accidents de applicaton au démarrage tout en manquant les fichiers dll. Si je les ajoute maintenant à mingw ou à l'application root l'application s'exécute, mais échoue à nouveau sur l'exécution de cmake tout en localisant les fichiers dll au lieu de .lib ...

Quelqu'un at-il une idée de comment je pourrais résoudre ce problème? Je serais profondément reconnaissant pour toute allusion. Cordialement, Christian

Répondre

0

Ce problème est résolu. Je dois rechercher le nom complet de la bibliothèque, c'est-à-dire libDevIL.lib dans mon script CMake. Dans ce cas, la bibliothèque se trouve correctement:

#Determine DevIL library 
FIND_LIBRARY(IL_LIBRARY NAMES libDEVIL.lib 
    PATH_SUFFIXES lib 
    PATHS c:/mingw 
    DOC "The file that corresponds to the base il library." 
) 
+0

Non ce n'est pas! L'un des principaux points de CMake est le développement multiplateforme, et l'ajout de lib le brise évidemment. Dans l'ensemble, cela ressemble à un bug dans cmake pour moi, je suppose qu'il devrait rechercher des fichiers lib même avec le générateur de générateur de mingw. – Slava

0

Placez ceci dans le fichier CMake racine de votre projet, de trouver premières bibliothèques .lib et alors seulement .dll.

IF(WIN32) 
    SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll) 
ELSE() 
    SET(CMAKE_FIND_LIBRARY_SUFFIXES .a) 
ENDIF() 

Je suppose qu'ils l'ont fait pour sauver certaines personnes de problèmes d'incompatibilité binaire, comme MinGW généré dll peuvent être utilisés par MinGW sans .lib. Aucune autre idée pourquoi ce n'est pas le comportement par défaut.