OpenGL renderers fail to crosscompile due to linking flag order

Issue #1131 new
Marvin Gülker
created an issue

Hi everyone,

I was trying to crosscompile CEGUI 0.8.x to include it into the MinGW-w64-based MXE crosscompilation toolchain for Windows. See my efforts in this ticket on the MXE tracker.

During the effort I came over several issues for which I'm probably going to file separate issues, but the most important one for now is that the OpenGLRenderer does not crosscompile because the order of the linking flags is wrong (sigh). GCC on Windows is very picky about the order in which you pass the -l flags. They must come from the most specialised to the most general, i.e. the libraries with most dependencies must come first, then must come its dependencies, and finally must come all libraries that do not have dependencies.

Currently, CEGUI's build system tries to build the OpenGLRenderer with a linking flag order of -lglu32 -lopengl32 -lGLEW. This is wrong and causes these errors:

/home/quintus/repos/privat/projekte/misc/mxe/usr/lib/gcc/i686-w64-mingw32.static/4.9.3/../../../../i686-w64-mingw32.static/lib/../lib/libGLEW.a(glew.o):glew.c:(.text+0x3c7): undefined reference to `_imp__wglGetProcAddress@4'
/home/quintus/repos/privat/projekte/misc/mxe/usr/lib/gcc/i686-w64-mingw32.static/4.9.3/../../../../i686-w64-mingw32.static/lib/../lib/libGLEW.a(glew.o):glew.c:(.text+0xe47): undefined reference to `_imp__wglGetProcAddress@4'
/home/quintus/repos/privat/projekte/misc/mxe/usr/lib/gcc/i686-w64-mingw32.static/4.9.3/../../../../i686-w64-mingw32.static/lib/../lib/libGLEW.a(glew.o):glew.c:(.text+0x18f7): undefined reference to `_imp__wglGetProcAddress@4'
/home/quintus/repos/privat/projekte/misc/mxe/usr/lib/gcc/i686-w64-mingw32.static/4.9.3/../../../../i686-w64-mingw32.static/lib/../lib/libGLEW.a(glew.o):glew.c:(.text+0x1d37): undefined reference to `_imp__wglGetProcAddress@4'
[... and so on...]

The correct order of the -l flags is -lGLEW -lglu32 -lopengl32. If passed in that order, the OpenGL Renderer compiles as it should (I tested it by manually modifying the linklibs.rsp file generated by CMake for the OpenGLRenderer, which is obviously not the correct way to do it).

  • Operating system: Gentoo Linux 64-bit
  • CEGUI 0.8.7 sourcecode vanilla from the CEGUI website

Steps to reproduce:

  1. Download MXE: $ git clone git://github.com/mxe/mxe.git && cd mxe
  2. Build CEGUI's dependencies: $ make gcc expat freeglut freeimage freetype libxml2 pcre xerces devil glm glew
  3. Build CEGUI .
  • The LibXML2 and TinyXML parsers won't build due to another issue, thus disable them.
  • CEGUI's build system fails to use pkg-config for freetype2 and glew, resulting in it not finding the nonstandard include path MXE uses for freetype2 and missing the -DGLEW_STATIC flag required for using GLEW with MXE. Thus we'll help the build system a little by adjusting CXXFLAGS.
  • The above were the issues I'll probably file extra tickets for.
$ mkdir build
$ cd build
$ export CXXFLAGS=`i686-w64-mingw32.static-pkg-config --cflags freetype2 glew`
$ i686-w64-mingw32.static-cmake  -DCEGUI_BUILD_XMLPARSER_LIBXML2=OFF -DCEGUI_BUILD_XMLPARSER_TINYXML=OFF ..`

Greetings Marvin

Comments (5)

  1. Yaron Cohen-Tal

    @Marvin Gülker: I'm glad u want to include cegui in your project. Thanx for reporting that problem. I indeed haven't tested cegui with static dependencies yet, therefore I haven't caught the issue. I've pushed a fix - plz test the head revision from cegui branch v0-8 and tell me if it fixes the issue.

  2. Marvin Gülker reporter

    @Yaron Cohen-Tal I tested with this commit:

    $ hg log -l1 
    changeset:   6363:bf699651740a
    branch:      v0-8
    tag:         tip
    user:        Yaron Cohen-Tal <yaronct@gmail.com>
    date:        Thu Jul 28 13:26:51 2016 +0300
    summary:     Fix OpenGL renderer dependencies order. Thanx to Marvin Gülker.
    

    This fixes the problem and the OpenGLRenderer compiles. Thank you! But please note that the OpenGLRenderer still requires manually adjusting the CXXFLAGS as described above, especially setting -DGLEW_STATIC is still required manually. If CEGUI would query pkg-config for GLEW, that would not happen. Likewise, freetype flags must be specified manually as shown above, but that's not directly related to the OpenGLRenderer (the build already fails in the Core library without this) and thus should have its own ticket I guess.

    Thanks! Marvin

  3. Marvin Gülker reporter

    I agree with your thoughts over in the freetype2-related ticket that certain flags need to be set by the builder if pkg-config is not in use. I think GLEW_STATIC qualifies as such a flag. So, unless you decide to query pkg-config, you can close this ticket because the main problem -- incorrect link flag order -- is resolved by your commit. Thank you again!

    Greetings Marvin

  4. Yaron Cohen-Tal

    @Marvin Gülker: As for using a static Glew - there's a cegui cmake option CEGUI_BUILD_SHARED_LIBS_WITH_STATIC_DEPENDENCIES that might help u. However, I wonder, why would u wanna build the cegui opengl renderer as a shared lib, linked to Glew as a static lib? If the cegui user needs to use Glew directly too, it becomes a mess!

  5. Marvin Gülker reporter

    However, I wonder, why would u wanna build the cegui opengl renderer as a shared lib, linked to Glew as a static lib? If the cegui user needs to use Glew directly too, it becomes a mess!

    To be honest, I am not entirely sure what exactly I am building. I don't have deep MXE knowledge and just poke around with the Makefile until I get the build to succeed... If I sound confused, that's because I am. That mixing shared and static libraries is not a good idea is something I know, though.

    Thanks for the hint on the option.

    Greetings Marvin

  6. Log in to comment