Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编译SDL2+;OpenGL&x2B;Windows上代码::块中的项目:未定义的引用_C++_Opengl_Gcc_Codeblocks_Sdl 2 - Fatal编程技术网

C++ 编译SDL2+;OpenGL&x2B;Windows上代码::块中的项目:未定义的引用

C++ 编译SDL2+;OpenGL&x2B;Windows上代码::块中的项目:未定义的引用,c++,opengl,gcc,codeblocks,sdl-2,C++,Opengl,Gcc,Codeblocks,Sdl 2,我正在检查创建使用OpenGL代码的windows应用程序的不同变体。我对OpenGL核心概要文件(即所谓的“现代OpenGL”)特别感兴趣。我使用Code::Blocks作为我的IDE 首先,我编写了一个简单的WinAPI应用程序。它工作得很好,直到我尝试运行一些核心代码。这向我展示了如果我想在Windows中使用现代OpenGL,WinAPI在这里不起作用,因为它是用即时模式修复的 所以,我的下一步是使用GLFW+GLAD(在站点上生成)创建一个项目。在这个过程中,OpenGL函数中有一些未

我正在检查创建使用OpenGL代码的windows应用程序的不同变体。我对OpenGL核心概要文件(即所谓的“现代OpenGL”)特别感兴趣。我使用Code::Blocks作为我的IDE

首先,我编写了一个简单的WinAPI应用程序。它工作得很好,直到我尝试运行一些核心代码。这向我展示了如果我想在Windows中使用现代OpenGL,WinAPI在这里不起作用,因为它是用即时模式修复的

所以,我的下一步是使用GLFW+GLAD(在站点上生成)创建一个项目。在这个过程中,OpenGL函数中有一些未解析的符号,但很高兴解决了这个问题,我的项目就完成了。编译和运行没有问题

这次我想测试一个SDL变体。我下载了SDL2头和库,并将它们放在C::B安装中正确的文件夹中。起初,我编写了一个简单的纯SDL2应用程序,它工作得很好,这向我表明,构建选项中包含库和库链接不会让编译器被我的代码阻塞

现在我添加了一些使用opengl核心函数的代码。最初编译代码时,编译器会抱怨这些函数。我通过再次添加“高兴”来解决这些问题,就像我以前的项目一样,它工作得很好,但只是编译。当试图链接我的程序时,编译器会抛出很多这样的错误:

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'
我很确定我在链接库时弄错了什么。也许他们的顺序不对。也许我错过了一些这可能是另一个错误

链接器选项中的我的库列表是:

mingw32
SDL2main
SDL2
glew32
opengl32
glu32

我不知道什么样的库是“\uu imp\u SetupDiGetClassDevsA”及其公司,因此我不知道该怎么办☹.

好的,我找到了问题所在。我发现有些人在互联网的不同部分问了类似的问题,所以我在这里发布了我自己问题的答案,这样其他人可能会发现(我希望他们会发现这很有用)

这些函数来自SDL2,它不想静态编译。 根据这篇文章,“正确的方法”是从sdl2包附带的
bin\
文件夹运行
sdl2配置。使用
--static libs
运行它应该会给我们一个链接器选项列表,这些选项将写入“构建选项…/linker settings/Other linker options”对话框。就我而言,它是:
-lmingw32-lSDL2main-lSDL2-mwindows-Wl,-无未定义-Wl,-dynamicbase-Wl,--nxcompat-Wl,-高熵va-lm-ldinput8-ldxguid-ldxerr8-luser32-lgdi32-lwinmm-limm32-lole32-loleaut32-lsetupapi-lversion-luuid-static libgcc
(这个列表比我在发帖中想的要长得多)


我之前没有找到它,因为
sdl2 config
是一个Bash文件,而code::Blocks附带的MinGW没有Bash解释器,所以我无法正常运行它。幸运的是,它是一个文本文件(而不是我第一次猜测的二进制程序),所以我只是搜索了它的正确行

最简单的解决方案是不静态链接lib。因为静态链接,所以需要针对SDL2的每个依赖项手动链接,大约有20个依赖项。请参见SDL随附的
sdl2.pc
,了解确切的标志。“我不知道什么是库”\uuu imp\u SetupDiGetClassDevsA“和它的公司”嗯,你可以用谷歌搜索函数名。“如果我想在Windows中使用现代OpenGL,WinAPI是没有用的”你确定吗?SDL在幕后使用WinAPI,它不能是其他任何东西。
glad
glew
。选择一个,但不要混合使用。@HolyBlackCat通过删除
-static
来说明您的解决方案是有效的,但仅当在code::Blocks中运行应用程序时有效。当我尝试手动运行程序时,它会抱怨“libwnpthread-1.dll”。我添加该标志是为了避免动态链接出现问题(但是,我在应用程序文件夹中明智地复制了sdl2.dll,因此它至少不会抱怨该标记)@Felix.leg也将该dll复制到应用程序文件夹中。它随编译器一起提供。您可能还需要
libgcc…dll
libstdc++…dll