1

I'm checking different variants of creating windows applications that use OpenGL code. I'm especially interested in OpenGL Core Profile (so called "modern OpenGL"). I'm using Code::Blocks as my IDE.

At first I coded a simple WinAPI application. It worked fine, until I tried to run some Core code. This showed me if I want to use modern OpenGL in Windows, WinAPI is not of use here, because it's fixed with Immediate mode.

So, my next step was to make a project using GLFW + GLAD (which is generated on https://glad.dav1d.de/ site). During this approach there was some unresolved symbols to OpenGL functions, but GLAD fixed this and my project was finished. Compile & Run without problems.

This time I want to test a SDL variant. I downloaded SDL2 headers and libraries and put them into right folders in C::B installation. At first I coded a simple SDL2 only application and it worked fine, which showed me that includes and links to libraries in the build options doesn't gets the compiler to choke with my code.

Now I added some code which uses opengl's core functions. At first compiling that code resulted in the compiler complaining about those functions. I resolved them by again adding GLAD, just like with my previous project, and it works fine, but only compiling. When trying to link my program, the compiler spits out a lots of these errors:

g++.exe  -o bin\Debug\OpenGL_SDL.exe obj\Debug\glad.o obj\Debug\main.o  -static-libstdc++ -static-libgcc -static -lmingw32 -lSDL2main -lSDL2 -lglew32 -opengl32 -lglu32 -mwindows  
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_hidapi.o): In function `PLATFORM_hid_enumerate':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/hidapi/windows/hid.c:354: undefined reference to `__imp_SetupDiGetClassDevsA'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/hidapi/windows/hid.c:354: undefined reference to `__imp_SetupDiEnumDeviceInterfaces'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/hidapi/windows/hid.c:378: undefined reference to `__imp_SetupDiGetDeviceInterfaceDetailA'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/hidapi/windows/hid.c:415: undefined reference to `__imp_SetupDiEnumDeviceInfo'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/hidapi/windows/hid.c:420: undefined reference to `__imp_SetupDiGetDeviceRegistryPropertyA'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/hidapi/windows/hid.c:565: undefined reference to `__imp_SetupDiDestroyDeviceInfoList'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/hidapi/windows/hid.c:427: undefined reference to `__imp_SetupDiGetDeviceRegistryPropertyA'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windows.o): In function `WIN_CoInitialize':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/core/windows/SDL_windows.c:76: undefined reference to `__imp_CoInitializeEx'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windows.o): In function `WIN_CoUninitialize':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/core/windows/SDL_windows.c:95: undefined reference to `__imp_CoUninitialize'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_SetupAPI':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:650: undefined reference to `ImmGetIMEFileNameA'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:663: undefined reference to `ImmGetContext'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:666: undefined reference to `ImmReleaseContext'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetId':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:584: undefined reference to `ImmGetIMEFileNameA'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:599: undefined reference to `GetFileVersionInfoSizeA'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:603: undefined reference to `GetFileVersionInfoA'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:604: undefined reference to `VerQueryValueA'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `UILess_GetCandidateList':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:1021: undefined reference to `__imp_SysFreeString'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:716: undefined reference to `ImmGetContext'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:720: undefined reference to `ImmNotifyIME'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:724: undefined reference to `ImmNotifyIME'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:725: undefined reference to `ImmReleaseContext'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:722: undefined reference to `ImmSetCompositionStringW'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Disable':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:404: undefined reference to `ImmAssociateContext'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `UIElementSink_BeginUIElement':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:1088: undefined reference to `__imp_SysFreeString'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `UIElementSink_UpdateUIElement':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:1115: undefined reference to `__imp_SysFreeString'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Init':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:348: undefined reference to `__imp_CoCreateInstance'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:363: undefined reference to `ImmGetContext'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:364: undefined reference to `ImmReleaseContext'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `UILess_SetupSinks':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:1229: undefined reference to `__imp_CoCreateInstance'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Quit':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:418: undefined reference to `ImmAssociateContext'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Enable':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:389: undefined reference to `ImmAssociateContext'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `WIN_SetTextInputRect':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:244: undefined reference to `ImmGetContext'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:251: undefined reference to `ImmSetCompositionWindow'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:252: undefined reference to `ImmReleaseContext'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_HandleMessage':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:889: undefined reference to `ImmGetContext'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetCompositionString':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:732: undefined reference to `ImmGetCompositionStringW'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:737: undefined reference to `ImmGetCompositionStringW'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_HandleMessage':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:927: undefined reference to `ImmReleaseContext'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetReadingString':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:459: undefined reference to `ImmGetContext'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:531: undefined reference to `ImmReleaseContext'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_HandleMessage':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:922: undefined reference to `ImmGetContext'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetCandidateList':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:800: undefined reference to `ImmGetCandidateListW'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:804: undefined reference to `ImmGetCandidateListW'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetCompositionString':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:732: undefined reference to `ImmGetCompositionStringW'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/video/windows/SDL_windowskeyboard.c:737: undefined reference to `ImmGetCompositionStringW'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_dinputhaptic.o): In function `SDL_DINPUT_HapticInit':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/haptic/windows/SDL_dinputhaptic.c:89: undefined reference to `__imp_CoCreateInstance'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_systimer.o): In function `SDL_SetSystemTimerResolution':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/timer/windows/SDL_systimer.c:57: undefined reference to `__imp_timeBeginPeriod'
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/timer/windows/SDL_systimer.c:51: undefined reference to `__imp_timeEndPeriod'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_systimer.o): In function `SDL_TicksInit':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/timer/windows/SDL_systimer.c:102: undefined reference to `__imp_timeGetTime'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libSDL2.a(SDL_systimer.o): In function `SDL_SetSystemTimerResolution':
/Users/valve/release/SDL/SDL2-2.0.12-source/foo-x64/../src/timer/windows/SDL_systimer.c:51: undefined reference to `__imp_timeEndPeriod'

I'm pretty sure I messed something in linking libraries. Maybe they are in the wrong order. Maybe I miss some. OR it may be another error enterly.

My library list in linkier options is:

mingw32
SDL2main
SDL2
glew32
opengl32
glu32

I don't know from what library is "__imp_SetupDiGetClassDevsA" and its company and thus I don't know what to do ☹.

Felix.leg
  • 622
  • 1
  • 4
  • 13
  • 1
    The simplest solution is to *not* link your libs statically. Because you link statically, you need to manually link against every dependency of SDL2, and there are like 20 of them. See `sdl2.pc` that comes with SDL for the exact flags. *"I don't know from what library is "__imp_SetupDiGetClassDevsA" and its company"* Well, you can google the function name. – HolyBlackCat May 02 '20 at 17:38
  • 1
    *"if I want to use modern OpenGL in Windows, WinAPI is not of use"* Are you sure? SDL uses WinAPI under the hood, it can't be anything else. – HolyBlackCat May 02 '20 at 17:42
  • `glad` or `glew`. Chose one but don't mix them. – Ripi2 May 02 '20 at 17:56
  • @HolyBlackCat your solution with removing ```-static``` worked, but only when running the application inside Code::Blocks. When I try to run my program manually it complains about 'libwnpthread-1.dll'. I added that flag on purpose to avoid problems with dynamic linking (however, I copied wisely sdl2.dll in the app's folder, so it doesn't complain about *that one* at least) – Felix.leg May 02 '20 at 18:25
  • @Felix.leg Copy that dll to the app's folder too. It's shipped with your compiler. You might also need `libgcc...dll` and `libstdc++...dll`. – HolyBlackCat May 02 '20 at 18:47

1 Answers1

6

OK, I found where lies the problem. I found some other people asked a similar question in different part of the Internet, so I'm posting an answer to my own question here, so others may find it (and I hope they will find this useful).

Those functions comes from SDL2 which didn't wanted to compile statically. According to this post Static-linking of SDL2 libraries the "proper way" is to run sdl2-config from bin\ folder shipped with the SDL2 package. Running it with --static-libs should give us a list of linker options to be written in "Build Options... / Linker settings / Other linker options" dialog. In my case it is: -lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--no-undefined -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid -static-libgcc (this is much longer list than I thought in my question post).

I didn't found it earlier because sdl2-config is a Bash file, and the MinGW shipped with Code::Blocks hasn't got Bash interpreter with it, so I couldn't run it normally. Fortunately, it is a text file (and not a binary program as I first guessed), so I just searched it for the right line.

Felix.leg
  • 622
  • 1
  • 4
  • 13