Jump to content


How to link DevIL DLL from MinGW using CMAKE?


4 replies to this topic

#1 hellhound_01

    New Member

  • Members
  • PipPip
  • 58 posts

Posted 23 August 2010 - 06:54 AM

Hi,

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

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'


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


But in this case the applicaton crashes on start up while missing the dll files. If i add those dlls back to mingw bin subfolder 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

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 23 August 2010 - 07:03 AM

I haven't used DevIL nor MinGW/CMAKE extensively, but a common gotcha I've run into before is C vs C++ linkage. It looks like your program is expecting DevIL to be C++ linked, i.e. linked with name mangling - double check that DevIL is not compiled with C linkage. I think most common libraries use C linkage due to the incompatibiliy of name mangling conventions between various C++ compilers. However, if you're compiling DevIL from source yourself you should be able to use C++ linkage without issue, if the library allows for it.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 hellhound_01

    New Member

  • Members
  • PipPip
  • 58 posts

Posted 23 August 2010 - 07:31 AM

This sounds logical but i think there is no problem with the linkage. I think there must be a Problem with CMake. Actually i use the precompiled library, maybe it help if i build it by myself...

But I am surprised that MinGW and G++ could be link to this library without any issue if i link it directly as compiler option without using CMake:


g++ winmain.cpp -o test -lglu32 -lopengl32 -ldevil



#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 23 August 2010 - 07:36 AM

Hmm, if that works then I agree the linkage does not seem to be the issue. I'm having a bit of trouble following your original description; your setup seems complicated. Unfortunately I'm not familiar enough with CMAKE to offer any more useful advice.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 hellhound_01

    New Member

  • Members
  • PipPip
  • 58 posts

Posted 23 August 2010 - 09:22 AM

Thanks for your support try Nathan. My configuration is not complicated, it's MinGW and CMake struff ;) For anyone who knowes CMake, here more details how i try to find the DevIL library:


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                # Extension to localize MinGW root

      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                 # Extension to localize MinGW root

     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})









1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users