Problème sur l'utilisation CMAKE avec MSYS / MinGW reliant les fichiers dll en utilisant la bibliothèque d'images DevIL

StackOverflow https://stackoverflow.com/questions/3537588

  •  30-09-2019
  •  | 
  •  

Question

en fait je créer un script CMake pour localiser la bibliothèque DevIL à l'aide de la plateforme win32 MSYS / MinGW. J'ai étendre l'origine FindDevIL scénario CMake à considérer la racine MinGW lorsque vous essayez de trouver 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 de DIABLE sont placés dans un sous-dossier bin, les fichiers DevIL.lib et DevIL.a dans le sous-répertoire lib de la racine MinGW (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

renvoie Find_libary () 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 `_imp__ilOriginFunc@4'
CMakeFiles/DevILTest.dir/winmain.cpp.obj:winmain.cpp:(.text+0xce0): undefined reference to `_imp__ilEnable@4'
CMakeFiles/DevILTest.dir/winmain.cpp.obj:winmain.cpp:(.text+0xcf9): undefined reference to `_imp__ilSetInteger@8'

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 le applicaton se bloque dans ce départ cas jusqu'à tout en manquant les fichiers dll. Si je les ajoute maintenant à MinGW ou racine de l'application d'exécution de l'application, mais échoue à nouveau sur l'exécution de CMake en localiser les fichiers dll au lieu de .lib ...

Quelqu'un at-il une idée comment je pouvais résoudre ce problème? Je serais profondément gratefull pour tout soupçon. Meilleures salutations, Christian

Était-ce utile?

La solution

Ce problème est résolu. J'ai pour rechercher le nom complet de la bibliothèque, à savoir 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."
)

Autres conseils

mettre ceci dans votre fichier cmake racine du projet, 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 dll générés MinGW peuvent être utilisés par MinGW sans .lib. Aucune autre idée pourquoi ce n'est pas le comportement par défaut.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top