我正在检查使用OpenGL代码创建Windows应用程序的不同变体。我对OpenGL Core Profile(所谓的“现代OpenGL”)特别感兴趣。我正在使用Code :: Blocks作为我的IDE。
首先,我编写了一个简单的WinAPI应用程序。在我尝试运行一些Core代码之前,它运行良好。这向我展示了如果我想在Windows中使用现代OpenGL,则此处不使用WinAPI,因为它已在即时模式下修复。
因此,我的下一步是使用GLFW + GLAD(在https://glad.dav1d.de/网站上生成)创建一个项目。在这种方法中,OpenGL函数有一些未解决的符号,但是GLAD修复了该问题,我的项目完成了。编译并运行没有问题。
这次我要测试SDL变体。我下载了SDL2标头和库,并将它们放在C :: B安装的正确文件夹中。最初,我编写了一个仅用于SDL2的简单应用程序,并且运行良好,向我展示了在构建选项中包含并链接到库的过程不会使编译器受我的代码困扰。
现在,我添加了一些使用opengl核心功能的代码。最初,编译该代码导致编译器抱怨这些功能。我像之前的项目一样,通过再次添加GLAD来解决了这些问题,并且效果很好,但只能编译。尝试链接程序时,编译器会吐出很多这些错误:
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'
我很确定我在链接库时搞砸了。也许他们的顺序错误。也许我想念一些。 OR 可能是另一个错误。
我的链接器选项中的图书馆列表是:
mingw32
SDL2main
SDL2
glew32
opengl32
glu32
我不知道哪个库是“ __imp_SetupDiGetClassDevsA”及其公司,因此我不知道该怎么办☹。
好的,我发现问题出在哪里。我发现其他人在Internet的不同部分也提出了类似的问题,因此我在这里发布了我自己的问题的答案,以便其他人可以找到(我希望他们会觉得有用)。
这些功能来自SDL2,它们不希望进行静态编译。根据这篇文章Static-linking of SDL2 libraries,“正确的方法”是从SDL2软件包附带的sdl2-config
文件夹中运行bin\
。使用--static-libs
运行它会给我们一个链接器选项列表,该列表将在“构建选项... /链接器设置/其他链接器选项”对话框中编写。以我为例:-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
(这比我在问题帖中认为的要长[[uch]]个列表)。我之前没有找到它,因为sdl2-config
是一个Bash文件,并且Code :: Blocks附带的MinGW尚未附带Bash解释器,因此我无法正常运行它。幸运的是,它是一个文本文件(而不是我最初猜到的二进制程序),因此我只是在其中搜索了右行。