Building on Linux with MinGW-w64

llynx
2013-04-17
2013-06-03
  • llynx
    llynx
    2013-04-17

    I'm having serious troubles building assimp3 from source using the i686-w64-mingw32 and x86_64-w64-mingw32 toolchains. I've changed the following settings in the CMakeLists.txt:

    SET(CMAKE_INSTALL_PREFIX "/usr/x86_64-w64-mingw32")
    set (CMAKE_CC_FLAGS "-m64 -O3") # Must enable -O3 in order to prevent "Section has too many headers" errors
    set (CMAKE_CXX_FLAGS "-m64 -O3")
    set (CMAKE_CC_COMPILER x86_64-w64-mingw32-gcc)
    set (CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
    SET ( BUILD_STATIC_LIB ON CACHE BOOL
    SET ( ENABLE_BOOST_WORKAROUND ON CACHE BOOL
    SET ( NO_EXPORT ON CACHE BOOL
    #Forced assimp's own zlib build
    SET ( BUILD_ASSIMP_TOOLS OFF CACHE BOOL

    The builds complete successfully however when I finally link the static libraries and compile my OpenGL program with basic model importing I get undefined reference errors:

    src/Mesh.o:Mesh.cpp:(.text+0x1d93): undefined reference to `Assimp::Importer::Importer()'
    etc.

    I am linking properly because it finds libassimp.so properly (complains with "cannot find -lassimp" error if libassimp.so is not found) however it is as though the library was not linked at all (I get the same errors if I remove assimp from the linker command)

    The same thing happens under the i686 build and I'm at a loss at this point. My linux-gnu-g++ builds went fine for 32-bit/64-bit

    Any suggestions?

     
  • JDDuke
    JDDuke
    2013-04-17

    It's a little odd that you've configured a static Assimp build, but are linking against a libassimp.so library.  Typically the .so suffix indicates a shared library; I haven't looked close enough at Assimp's CMake configuration to see how it configures MinGW builds.  Does the build only generate libassimp.so? No .a static library?

     
  • llynx
    llynx
    2013-04-18

    my mistake in writing the post, it generates libassimp.a as expected and it links to it correctly.

    I managed to get past some undefined reference errors by changing some of the options to the following:

    SET(CMAKE_SYSTEM_NAME    Windows) # Target system name
    SET(CMAKE_C_COMPILER     "x86_64-w64-mingw32-gcc")
    SET(CMAKE_CXX_COMPILER   "x86_64-w64-mingw32-g++")
    SET(CMAKE_RC_COMPILER    "x86_64-w64-mingw32-windres")
    SET(CMAKE_RANLIB         "x86_64-w64-mingw32-ranlib")
    SET(CMAKE_INSTALL_PREFIX "/usr/x86_64-w64-mingw32")

    set (CMAKE_CC_FLAGS "-m64 -O3")
    set (CMAKE_CXX_FLAGS "-m64 -O3")

    # Configure the behaviour of the find commands
    SET(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32")
    SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

    It now takes a while when its processing the library for my project instead of instantly jumping to undefined reference errors.

    However I get new undefined reference errors:

    /home/admin/workspace/engine/lib/x86_64-w64-mingw32/libassimp.a(ScenePreprocessor.cpp.o):ScenePreprocessor.cpp:(.text+0x1222): undefined reference to `aiReturn aiMaterial::AddProperty<aiColor3D>(aiColor3D const*, unsigned int, char const*, unsigned int, unsigned int)'
    /home/admin/workspace/engine/lib/x86_64-w64-mingw32/libassimp.a(B3DImporter.cpp.o):B3DImporter.cpp:(.text+0x37fd): undefined reference to `aiReturn aiMaterial::AddProperty<aiVector3t<float> >(aiVector3t<float> const*, unsigned int, char const*, unsigned int, unsigned int)'
    /home/admin/workspace/engine/lib/x86_64-w64-mingw32/libassimp.a(B3DImporter.cpp.o):B3DImporter.cpp:(.text+0x382f): undefined reference to `aiReturn aiMaterial::AddProperty<float>(float const*, unsigned int, char const*, unsigned int, unsigned int)'
    /home/admin/workspace/engine/lib/x86_64-w64-mingw32/libassimp.a(B3DImporter.cpp.o):B3DImporter.cpp:(.text+0x3882): undefined reference to `aiReturn aiMaterial::AddProperty<aiColor3D>(aiColor3D const*, unsigned int, char const*, unsigned int, unsigned int)'
    /home/admin/workspace/engine/lib/x86_64-w64-mingw32/libassimp.a(B3DImporter.cpp.o):B3DImporter.cpp:(.text+0x38cb): undefined reference to `aiReturn aiMaterial::AddProperty<float>(float const*, unsigned int, char const*, unsigned int, unsigned int)'
    /home/admin/workspace/engine/lib/x86_64-w64-mingw32/libassimp.a(B3DImporter.cpp.o):B3DImporter.cpp:(.text+0x3b01): undefined reference to `aiReturn aiMaterial::AddProperty<int>(int const*, unsigned int, char const*, unsigned int, unsigned int)'

    Any thoughts?

     
  • JDDuke
    JDDuke
    2013-04-18

    Interesting, that looks like a bug; those template functions are not specialized  when ASSIMP_BUILD_NO_EXPORT is defined, but they appear to be used by import methods. 

    As a workaround, you might try removing the "#ifndef ASSIMP_BUILD_NO_EXPORT" guard in include/assimp/material.inl.  I'll submit a pull request to fix this. 

     
  • llynx
    llynx
    2013-04-18

    That did the trick! Thanks!

    However after inclusion of assimp3, the program crashes under Wine but works on windows.
    setting SET(CMAKE_SYSTEM_NAME Windows) to linux doesn't affect program runtime on windows or linux. Probably is a wine issue now.

     
  • JDDuke
    JDDuke
    2013-04-18

    If you can get some kind of a stack trace for the crash that would be helpful.  Does it crash immediately on startup, or when the library is actually used in some explicit way?

     
  • llynx
    llynx
    2013-04-18

    Turned out to be a more serious opengl related driver issue due to updated packages.

    Assimp works fine now!  Thanks again jdduke!

    However I should note all the changes I had to make in order to get assimp to compile with w64-mingw32 on linux for anyone else who wants to do this in the future.

    1. Change '#include <string>' in 'include/assimp/types.h' to '#include <cstring>' if you run into ::strlen not defined errors (this does not happen on regular native compilers, only mingw).

    2. Using the CMAKE gui configuration generator always fails to configure using my my w64-mingw32-toolchain.cmake file and results always with 'Cannot compile a simple program' errors for both x86_64 and i686 w64-mingw32-gcc compilers. You must use the console cmake commands and edit CMakeLists.txt by hand.

    3. Regardless of ASSIMP_NO_EXPORT status (ON/OFF), applied workaround in post 4 above in order to avoid undefined reference errors in post 3 above.

    4. In order to generate the unix makefiles correctly the following was added. (Change x86_64 to i686 for 32-bit build)

    SET(CMAKE_SYSTEM_NAME    Linux) # Target system name, but setting this doesn't seem to matter
    SET(CMAKE_C_COMPILER     "x86_64-w64-mingw32-gcc")
    SET(CMAKE_CXX_COMPILER   "x86_64-w64-mingw32-g++")
    SET(CMAKE_RC_COMPILER    "x86_64-w64-mingw32-windres")
    SET(CMAKE_RANLIB         "x86_64-w64-mingw32-ranlib")

    # Set Compiler Flags
    # Requires -O3 flag to prevent 'File too big/too many sections' errors (i686 works fine without these flags in my case)
    set (CMAKE_CC_FLAGS "-O3")
    set (CMAKE_CXX_FLAGS "-O3")

    # Configure the behaviour of the find commands
    SET(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32")
    SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

    5. run: cmake -G 'Unix Makefiles'

     
  • JDDuke
    JDDuke
    2013-04-19

    Thanks for the update lllynx.  I've used CMake with MinGW64 to compile Assimp, but only on Windows, and I can't recall if I ran into any issues.  It shouldn't be too difficult to tweak the CMake script to accommodate MinGW builds out of the box, on both Windows and Linux.  I'll try to take a pass at it in the near future.

     
  • JDDuke
    JDDuke
    2013-04-19

    Thanks for the update lllynx.  I've used CMake with MinGW64 to compile Assimp, but only on Windows, and I can't recall if I ran into any issues.  It shouldn't be too difficult to tweak the CMake script to accommodate MinGW builds out of the box, on both Windows and Linux.  I'll try to take a pass at it in the near future.