MINGW-packages: [angleproject] linking fails in mingw32 with undefined symbols

Description / Steps to reproduce the issue

When attempting to link an sdl2/gles2 hello world against ANGLE’s GLESv2, I get a bunch of undefined references.

$ gcc sdl2gles2tri.c -lmingw32 -mwindows -lSDL2main -lSDL2 -lGLESv2
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x49): undefined reference to `_imp__glCreateShader@4'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x83): undefined reference to `_imp__glShaderSource@16'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x93): undefined reference to `_imp__glCompileShader@4'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0xb2): undefined reference to `_imp__glGetShaderiv@12'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0xe3): undefined reference to `_imp__glGetShaderiv@12'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x11f): undefined reference to `_imp__glGetShaderInfoLog@16'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x14d): undefined reference to `_imp__glDeleteShader@4'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x236): undefined reference to `_imp__glCreateProgram@0'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x25d): undefined reference to `_imp__glAttachShader@8'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x274): undefined reference to `_imp__glAttachShader@8'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x294): undefined reference to `_imp__glBindAttribLocation@12'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x2a4): undefined reference to `_imp__glLinkProgram@4'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x2c6): undefined reference to `_imp__glGetProgramiv@12'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x300): undefined reference to `_imp__glGetProgramiv@12'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x345): undefined reference to `_imp__glGetProgramInfoLog@16'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x373): undefined reference to `_imp__glDeleteProgram@4'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x39b): undefined reference to `_imp__glClearColor@16'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x416): undefined reference to `_imp__glViewport@16'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x427): undefined reference to `_imp__glClear@4'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x437): undefined reference to `_imp__glUseProgram@4'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x46f): undefined reference to `_imp__glVertexAttribPointer@24'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x480): undefined reference to `_imp__glEnableVertexAttribArray@4'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x4a1): undefined reference to `_imp__glDrawArrays@12'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x5c6): undefined reference to `_imp__glGetError@0'
C:/msys64/mingw32/bin/sdl2gles2tri.c:(.text+0x5e5): undefined reference to `_imp__glGetError@0'

Expected behavior

Proper linkage.

Actual behavior

As mentioned, failure to resolve ABI.

Other relevant information, ANGLE’s libraries don’t seem to export these symbols.

$ nm -g libGLESv2.dll.a | grep _imp__glCreateShader@4
(no output)
$ nm -g libGLESv2.dll.a | grep glCreateShader
00000000 I __imp__glCreateShaderProgramvEXT
00000000 T _glCreateShaderProgramvEXT
00000000 I __imp__glCreateShaderProgramv
00000000 T _glCreateShaderProgramv
00000000 I __imp__glCreateShader
00000000 T _glCreateShader

I’m not sure where the source of this @4 is being introduced, but the number of underscores at the beginning of the function signature seems incorrect too. I’ve only tried on MINGW32, as SDL seems to require linking against specifically the 32bit mingw library.

Verification

Windows Version

MINGW32_NT-10.0-22621

MINGW environments affected

  • MINGW64
  • MINGW32
  • UCRT64
  • CLANG64
  • CLANG32
  • CLANGARM64

Are you willing to submit a PR?

If I can determine the solution, absolutely

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 27 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Ok, thanks. It has been few days I assumed it is already there, but it was still in queue. It is working now.

I should note that while this sample works fine on linux with actual GLES2, I have yet to get it to truly work with ANGLE. The closest I’ve gotten on two linux distros and windows is a black screen.

For the record, the problem here was that I wasn’t setting the OPENGL_ES_DRIVER hint: https://github.com/msys2/MINGW-packages/issues/16971#issuecomment-1526043613. After adding that, it draws just fine.

Additionally, I’ve opened a thread in the ANGLE google group: https://groups.google.com/g/angleproject/c/gOdOOMTce_w

If I get no traction there, I’ll start working on a .def patch

If those symbols are really exported with __stdcall calling convention, but the library is linked with that .def file, that might be the reason for the issue here. It would probably need to use a .def file with the correctly mangled names on 32-bit platforms. See also, e.g., the patch that is applied for the vulkan-loader package: https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-vulkan-loader