Search code examples
cgccglewdwm

Error Linking GLEW and DWMAPI to MSYS MinGW


I am having trouble compiling a SDL+OpenGL program using gcc. I attempted to compile the program using this command:

g++ -static -o bin/main src/main.cpp src/core/*.cpp -I src/core/include -lglew32 sdl2-config --cflags --static-libs

However this just results in the following error messages:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccWjFpWW.o:application.cc:(.text+0x19fcb): undefined reference to `__imp_glewExperimental'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccWjFpWW.o:application.cc:(.text+0x19fd5): undefined reference to `__imp_glewInit'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccWjFpWW.o:application.cc:(.text+0x19fe1): undefined reference to `glEnable'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccWjFpWW.o:application.cc:(.text+0x19feb): undefined reference to `glDisable'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccWjFpWW.o:application.cc:(.text+0x1a012): undefined reference to `glClearColor'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccWjFpWW.o:application.cc:(.text+0x1a035): undefined reference to `glViewport'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccWjFpWW.o:application.cc:(.text+0x1a255): undefined reference to `glPolygonMode'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccWjFpWW.o:application.cc:(.text+0x1a2b9): undefined reference to `__imp___glewDeleteVertexArrays'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccWjFpWW.o:application.cc:(.text+0x1a2d2): undefined reference to `__imp___glewDeleteBuffers'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccx2gfol.o:graphics.cc:(.text+0x12): undefined reference to `glClear'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccx2gfol.o:graphics.cc:(.text+0x19): undefined reference to `__imp___glewUseProgram'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccx2gfol.o:graphics.cc:(.text+0x2e): undefined reference to `__imp___glewBindVertexArray'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccx2gfol.o:graphics.cc:(.text+0x51): undefined reference to `glDrawArrays'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccx2gfol.o:graphics.cc:(.text+0x58): undefined reference to `__imp___glewBindVertexArray'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccT87FYg.o:imgui_impl_win32.cc:(.text+0x228c): undefined reference to `DwmIsCompositionEnabled'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccT87FYg.o:imgui_impl_win32.cc:(.text+0x22d4): undefined reference to `DwmGetColorizationColor'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccT87FYg.o:imgui_impl_win32.cc:(.text+0x234f): undefined reference to `DwmEnableBlurBehindWindow'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\adam\AppData\Local\Temp\ccT87FYg.o:imgui_impl_win32.cc:(.text+0x238f): undefined reference to `DwmEnableBlurBehindWindow'

According to the errors, the compiler apparently cannot find any of the GLEW and DWMAPI functions and I want to ask where I'm going wrong with linking GLEW to the project and how I am supposed to link the DWMAPI to the project.

For more context, I am using MinGW with MSYS2. I have the SDL2, GLEW, and MinGW Header packages installed using pacman.


Also, the project successfully compiled when I was just using SDL2. I successfully linked and compiled this basic window creation script:

#include <SDL2/SDL.h>

int main(int argc, char *argv[]) {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* window = SDL_CreateWindow("Basic Window", 100, 100, 320, 240, SDL_WINDOW_SHOWN);
    SDL_Delay(1000);
    SDL_Quit();
    return 0;
}

Using this gcc command:

gcc -static -o basic.exe "SDL.c" sdl2-config --cflags --static-libs


Solution

  • Just add -ldwmapi to your compile command.