关于使用DevIL映像库将CMAKE与MSYS/MinGW链接dll文件一起使用的问题 [英] Issue on using CMAKE with MSYS/MinGW linking dll files using DevIL image library

查看:123
本文介绍了关于使用DevIL映像库将CMAKE与MSYS/MinGW链接dll文件一起使用的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我创建了一个CMake脚本,用于在Win32平台上使用MSYS/MinGW本地化DevIL库.我已经扩展了原始FindDevIL CMake脚本,以在尝试查找DevIL时将MinGW的根视为:

actually i create a CMake script to localize the DevIL library using MSYS/MinGW on win32 platform. I've extend the origin FindDevIL CMake script to regard the MinGW root when try to find 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})

DevIL .dll文件放在MinGW根目录(c:/mingw)的bin子文件夹中的bin子文件夹中,DevIL.lib和DevIL.a文件中.我使用find_library()检查库是否存在.

The DevIL .dll files are placed in bin subfolder, the DevIL.lib and DevIL.a files in the lib subfolder of MinGW root (c:/mingw). I use find_library() to check if a library exists.

-- 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()始终返回dll文件的路径-但我无法使用MinGW链接到该库:

Find_libary() returns allways the path to the dll files - but I can't link against this library using 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'

如果我删除dll文件并运行cmake skript,则DevIL.lib库已正确本地化,并且我没有链接器失败:

If i remove the dll files and run the cmake skript the DevIL.lib library is localized correctly and i go no linker failures:

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

但是在这种情况下,applicaton在启动时崩溃,而缺少dll文件.如果我现在将它们添加回mingw或应用程序根目录,则该应用程序将运行,但在本地执行dll文件而不是.lib的同时执行cmake执行时再次失败...

But when in this case the applicaton crashes on start up while missing the dll files. If i add them now back to mingw or application root the application runs, but fails again on cmake execution while localize the dll files instead of .lib ...

有人知道我该如何解决这个问题? 如有任何暗示,我将不胜感激. 最好的祝福, 基督徒

Has anyone an idea how i could solve this issue? I would be deeply gratefull for any hint. Best regards, Christian

推荐答案

此问题已解决.我必须在我的CMake脚本中搜索该库的完整名称,即libDevIL.lib.在这种情况下,可以正确找到该库:

This problem is solved. I've to search for the complete name of the library, i.e. libDevIL.lib in my CMake script. In this case the library is found correctly:

#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."
)

这篇关于关于使用DevIL映像库将CMAKE与MSYS/MinGW链接dll文件一起使用的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆