c-将GLEW和DWMAPI链接到MSYS MinGW时出错



我在使用gcc编译SDL+OpenGL程序时遇到问题。我试图使用以下命令编译程序:

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

然而,这只会导致以下错误消息:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersadamAppDataLocalTempccWjFpWW.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:UsersadamAppDataLocalTempccWjFpWW.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:UsersadamAppDataLocalTempccWjFpWW.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:UsersadamAppDataLocalTempccWjFpWW.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:UsersadamAppDataLocalTempccWjFpWW.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:UsersadamAppDataLocalTempccWjFpWW.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:UsersadamAppDataLocalTempccWjFpWW.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:UsersadamAppDataLocalTempccWjFpWW.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:UsersadamAppDataLocalTempccWjFpWW.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:UsersadamAppDataLocalTempccx2gfol.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:UsersadamAppDataLocalTempccx2gfol.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:UsersadamAppDataLocalTempccx2gfol.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:UsersadamAppDataLocalTempccx2gfol.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:UsersadamAppDataLocalTempccx2gfol.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:UsersadamAppDataLocalTempccT87FYg.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:UsersadamAppDataLocalTempccT87FYg.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:UsersadamAppDataLocalTempccT87FYg.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:UsersadamAppDataLocalTempccT87FYg.o:imgui_impl_win32.cc:(.text+0x238f): undefined reference to `DwmEnableBlurBehindWindow'

根据错误,编译器显然找不到任何GLEW和DWMAPI函数,我想问我将GLEW链接到项目时哪里出了问题,以及应该如何将DWMAPI链接到项目。

为了了解更多上下文,我将MinGW与MSYS2一起使用。我使用pacman安装了SDL2、GLEW和MinGW Header包。


此外,该项目在我刚使用SDL2时成功编译。我成功地链接并编译了这个基本的窗口创建脚本:

#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;
}

使用这个gcc命令:

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

只需将-ldwmapi添加到编译命令中即可。

相关内容

  • 没有找到相关文章

最新更新