简体   繁体   English

OpenGL 扩展未链接到 Windows

[英]OpenGL extensions not linking on Windows

I'm trying to link OpenGL to an application for Windows (building on Windows).我正在尝试将 OpenGL 链接到 Windows 的应用程序(在 Windows 上构建)。

I'm using Conan as package manager, CMake for building and MSVC as compiler (and CLion as IDE).我使用柯南作为 package 管理器,CMake 用于构建和 MSVC 作为编译器(和 CLion 作为 IDE)。

The program compiles, but I have linker errors, for what I believe to be extension functions in OpenGL:该程序编译,但我有 linker 错误,我认为是 OpenGL 中的扩展功能:

imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glBlendEquation referenced in function "void __cdecl ImGui_ImplOpenGL3_SetupRenderState(struct ImDrawData *,int,int,unsigned int)" (?ImGui_ImplOpenGL3_SetupRenderState@@YAXPEAUImDrawData@@HHI@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glActiveTexture referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glBlendFuncSeparate referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glBindBuffer referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glDeleteBuffers referenced in function "void __cdecl ImGui_ImplOpenGL3_DestroyDeviceObjects(void)" (?ImGui_ImplOpenGL3_DestroyDeviceObjects@@YAXXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glGenBuffers referenced in function "bool __cdecl ImGui_ImplOpenGL3_CreateDeviceObjects(void)" (?ImGui_ImplOpenGL3_CreateDeviceObjects@@YA_NXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glBufferData referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glBlendEquationSeparate referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glAttachShader referenced in function "bool __cdecl ImGui_ImplOpenGL3_CreateDeviceObjects(void)" (?ImGui_ImplOpenGL3_CreateDeviceObjects@@YA_NXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glCompileShader referenced in function "bool __cdecl ImGui_ImplOpenGL3_CreateDeviceObjects(void)" (?ImGui_ImplOpenGL3_CreateDeviceObjects@@YA_NXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glCreateProgram referenced in function "bool __cdecl ImGui_ImplOpenGL3_CreateDeviceObjects(void)" (?ImGui_ImplOpenGL3_CreateDeviceObjects@@YA_NXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glCreateShader referenced in function "bool __cdecl ImGui_ImplOpenGL3_CreateDeviceObjects(void)" (?ImGui_ImplOpenGL3_CreateDeviceObjects@@YA_NXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glDeleteProgram referenced in function "void __cdecl ImGui_ImplOpenGL3_DestroyDeviceObjects(void)" (?ImGui_ImplOpenGL3_DestroyDeviceObjects@@YAXXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glDeleteShader referenced in function "void __cdecl ImGui_ImplOpenGL3_DestroyDeviceObjects(void)" (?ImGui_ImplOpenGL3_DestroyDeviceObjects@@YAXXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glDetachShader referenced in function "void __cdecl ImGui_ImplOpenGL3_DestroyDeviceObjects(void)" (?ImGui_ImplOpenGL3_DestroyDeviceObjects@@YAXXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glEnableVertexAttribArray referenced in function "void __cdecl ImGui_ImplOpenGL3_SetupRenderState(struct ImDrawData *,int,int,unsigned int)" (?ImGui_ImplOpenGL3_SetupRenderState@@YAXPEAUImDrawData@@HHI@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glGetAttribLocation referenced in function "bool __cdecl ImGui_ImplOpenGL3_CreateDeviceObjects(void)" (?ImGui_ImplOpenGL3_CreateDeviceObjects@@YA_NXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glGetProgramiv referenced in function "bool __cdecl CheckProgram(unsigned int,char const *)" (?CheckProgram@@YA_NIPEBD@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glGetProgramInfoLog referenced in function "bool __cdecl CheckProgram(unsigned int,char const *)" (?CheckProgram@@YA_NIPEBD@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glGetShaderiv referenced in function "bool __cdecl CheckShader(unsigned int,char const *)" (?CheckShader@@YA_NIPEBD@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glGetShaderInfoLog referenced in function "bool __cdecl CheckShader(unsigned int,char const *)" (?CheckShader@@YA_NIPEBD@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glGetUniformLocation referenced in function "bool __cdecl ImGui_ImplOpenGL3_CreateDeviceObjects(void)" (?ImGui_ImplOpenGL3_CreateDeviceObjects@@YA_NXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glLinkProgram referenced in function "bool __cdecl ImGui_ImplOpenGL3_CreateDeviceObjects(void)" (?ImGui_ImplOpenGL3_CreateDeviceObjects@@YA_NXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glShaderSource referenced in function "bool __cdecl ImGui_ImplOpenGL3_CreateDeviceObjects(void)" (?ImGui_ImplOpenGL3_CreateDeviceObjects@@YA_NXZ)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glUseProgram referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glUniform1i referenced in function "void __cdecl ImGui_ImplOpenGL3_SetupRenderState(struct ImDrawData *,int,int,unsigned int)" (?ImGui_ImplOpenGL3_SetupRenderState@@YAXPEAUImDrawData@@HHI@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glUniformMatrix4fv referenced in function "void __cdecl ImGui_ImplOpenGL3_SetupRenderState(struct ImDrawData *,int,int,unsigned int)" (?ImGui_ImplOpenGL3_SetupRenderState@@YAXPEAUImDrawData@@HHI@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glVertexAttribPointer referenced in function "void __cdecl ImGui_ImplOpenGL3_SetupRenderState(struct ImDrawData *,int,int,unsigned int)" (?ImGui_ImplOpenGL3_SetupRenderState@@YAXPEAUImDrawData@@HHI@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glGetStringi referenced in function "bool __cdecl ImGui_ImplOpenGL3_Init(char const *)" (?ImGui_ImplOpenGL3_Init@@YA_NPEBD@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glBindVertexArray referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glDeleteVertexArrays referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glGenVertexArrays referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glDrawElementsBaseVertex referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glBindSampler referenced in function "void __cdecl ImGui_ImplOpenGL3_RenderDrawData(struct ImDrawData *)" (?ImGui_ImplOpenGL3_RenderDrawData@@YAXPEAUImDrawData@@@Z)
soundstate.exe : fatal error LNK1120: 34 unresolved externals

I think I've been around the entire internet searching for a solution, but I fail to understand what's missing.我想我一直在整个互联网上寻找解决方案,但我不明白缺少什么。 My hunch is currently that OpenGL extensions are not linked (being an OpenGL rookie, I'm not 100% sure what that even means).我的预感目前是 OpenGL 扩展未链接(作为 OpenGL 新手,我不能 100% 确定这甚至意味着什么)。

I'm compiling with GL_GLEXT_PROTOTYPES=1 .我正在使用GL_GLEXT_PROTOTYPES=1进行编译。

This is the linker command being executed:这是正在执行的 linker 命令:

C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1429~1.300\bin\Hostx86\x64\link.exe /nologo @CMakeFiles\soundstate.dir\objects1.rsp /out:soundstate.exe /implib:soundstate.lib /pdb:<project dir>\cmake-build-debug\soundstate.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console core.lib ..\vendor\fmod\windows\lib\x64\fmodL_vc.lib <user dir>\.conan\data\imgui-docking\1.83\trololo\stable\package\846e49ae2c2d7b4448ca2380ea2b4c7a382d695b\lib\imgui.lib <user dir>\.conan\data\sdl2\2.0.14\bincrafters\stable\package\a5e24820448cb570d848a2e59f317dd7edebe889\lib\SDL2maind.lib <user dir>\.conan\data\sdl2\2.0.14\bincrafters\stable\package\a5e24820448cb570d848a2e59f317dd7edebe889\lib\SDL2d.lib user32.lib gdi32.lib winmm.lib imm32.lib ole32.lib oleaut32.lib version.lib uuid.lib advapi32.lib setupapi.lib shell32.lib <user dir>\.conan\data\libiconv\1.16\_\_\package\d057732059ea44a47760900cb5e4855d2bea8714\lib\iconv.lib C:\Users\simon\.conan\data\libiconv\1.16\_\_\package\d057732059ea44a47760900cb5e4855d2bea8714\lib\charset.lib <user dir>\.conan\data\glew\2.2.0\_\_\package\2cd10aa7b17419a389740c9a9a85afec1178e5cf\lib\libglew32d.lib opengl32.lib Glu32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\soundstate.dir/intermediate.manifest CMakeFiles\soundstate.dir/manifest.res

I have tried:我努力了:

  • Using mingw (results in same linker errors)使用 mingw(导致相同的 linker 错误)
  • Adding GLEW添加 GLEW
  • Using shared SDL2 lib使用共享 SDL2 库
  • Finding a glext.lib x64 version (not sure it exists or needed)寻找 glext.lib x64 版本(不确定它是否存在或需要)

This is my CMakeLists.txt这是我的 CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(soundstate C CXX)
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})

find_package(imgui REQUIRED CONFIG)
find_package(SDL2 REQUIRED CONFIG)
find_package(immer REQUIRED CONFIG)
find_package(cereal REQUIRED CONFIG)
find_package(Boost REQUIRED CONFIG)
find_package(rxcpp REQUIRED CONFIG)
find_package(range-v3 REQUIRED CONFIG)
find_package(opengl_system REQUIRED CONFIG)
find_package(glew REQUIRED CONFIG)

#
# FMOD
#
set(CMAKE_VERBOSE_MAKEFILE ON)
if (WIN32)
    add_library(fmod STATIC IMPORTED)
    set_target_properties(fmod PROPERTIES
            LINKER_LANGUAGE C
            INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/vendor/fmod/linux/inc
            IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/vendor/fmod/windows/lib/x64/fmodL_vc.lib
            )
else ()
    file(COPY vendor/fmod/linux/lib/x86_64/libfmodL.so.12.9 DESTINATION ${CMAKE_BINARY_DIR}/resources/lib)
    set_target_properties(fmod PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/resources/lib/libfmodL.so)
endif ()

#
# Core
#
set(CORE_SOURCES
        core/model.h
        core/actions.h
        core/reducers.h
        core/utils.h core/utils.cpp
        core/reducers.cpp
        core/cursors.h core/cursors.cpp
        core/io.cpp core/io.h
        core/serialization.h
        core/audio/audio_engine.cpp core/audio/audio_engine.h
        core/audio/audio_context.cpp core/audio/audio_context.h)

add_library(core STATIC ${CORE_SOURCES})

target_include_directories(core PUBLIC include)
target_include_directories(core PUBLIC ${CONAN_INCLUDE_DIRS})

set(CORE_LIBS
        immer::immer
        cereal::cereal
        Boost::Boost
        rxcpp::rxcpp
        range-v3::range-v3
        )

set(ALL_LIBS
        imgui::imgui
        SDL2::SDL2
        immer::immer
        cereal::cereal
        Boost::Boost
        rxcpp::rxcpp
        range-v3::range-v3
        opengl::opengl
        GLEW::GLEW
        )

target_link_libraries(core fmod ${CORE_LIBS})


#
# Main
#
set(SOURCES
        ui/imgui/main.cpp
        ui/imgui/panels/panel.cpp ui/imgui/panels/panel.h
        ui/imgui/panels/playables_tree_panel.cpp ui/imgui/panels/playables_tree_panel.h
        ui/imgui/gui_manager.cpp ui/imgui/gui_manager.h
        ui/imgui/panels/playable_editor_panel.cpp ui/imgui/panels/playable_editor_panel.h
        ui/imgui/editors/editor.cpp ui/imgui/editors/editor.h
        ui/imgui/editors/file_playable_editor.cpp ui/imgui/editors/file_playable_editor.h
        ui/imgui/editors/list_playable_editor.cpp ui/imgui/editors/list_playable_editor.h
        ui/imgui/editors/state_editor.cpp ui/imgui/editors/state_editor.h
        ui/imgui/editors/state_option_editor.cpp ui/imgui/editors/state_option_editor.h
        ui/imgui/imgui_extras.h
        ui/imgui/icons_fa5.h
        include/ImGuiFileDialog/ImGuiFileDialog.cpp
        ui/imgui/panels/state_list_panel.cpp
        ui/imgui/panels/state_list_panel.h
        ui/imgui/panels/debug_panel.cpp
        ui/imgui/panels/debug_panel.h
        ui/imgui/panels/controls_panel.cpp
        ui/imgui/panels/controls_panel.h
        bindings/imgui_impl_opengl3.h
        bindings/imgui_impl_opengl3.cpp
        bindings/imgui_impl_sdl.h
        bindings/imgui_impl_sdl.cpp
        bindings/imgui_stdlib.h
        bindings/imgui_stdlib.cpp
        )

add_executable(soundstate ${SOURCES})

target_include_directories(soundstate PUBLIC vendor)
# Configure Imgui to use OpengGL through SDL2
target_compile_definitions(soundstate PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM=<SDL_opengl.h> GL_GLEXT_PROTOTYPES=1)
target_link_libraries(soundstate core ${ALL_LIBS})

# Copy resources
file(COPY resources/fonts/Roboto-Regular.ttf DESTINATION ${CMAKE_BINARY_DIR}/resources/fonts)
file(COPY resources/fonts/fa-regular-400.ttf DESTINATION ${CMAKE_BINARY_DIR}/resources/fonts)
file(GLOB AUDIO_FILES resources/audio/*)
file(COPY ${AUDIO_FILES} DESTINATION ${CMAKE_BINARY_DIR}/resources/audio)
file(COPY vendor/fmod/windows/lib/x64/fmodL.dll DESTINATION ${CMAKE_BINARY_DIR}/resources/lib)
file(COPY vendor/fmod/windows/lib/x64/fmodL_vc.lib DESTINATION ${CMAKE_BINARY_DIR}/resources/lib)

I'm compiling with GL_GLEXT_PROTOTYPES=1 .我正在使用GL_GLEXT_PROTOTYPES=1进行编译。

Well, don't do that.好吧,不要那样做。 That is never going to work in a portable way.这永远不会以便携的方式工作。 On windows, the opengl32.dll always exports only the functions which are in OpenGL 1.1, and for everything beyond that, you have to rely to the OpenGL extension loading mechanism at runtime . On windows, the opengl32.dll always exports only the functions which are in OpenGL 1.1, and for everything beyond that, you have to rely to the OpenGL extension loading mechanism at runtime .

I have tried:我努力了:

  • [...] [...]
  • Adding GLEW添加 GLEW

That's a step in the right direction.这是朝着正确方向迈出的一步。 But this does not make things to magically work.但这并不能使事情神奇地起作用。 A GL loader like GLEW typically brings its own header as a replacement for GL.h and glext.h etc., and the typical GL loader (like GLEW) simply re-define every GL functions as a macro, like this:像 GLEW 这样的 GL 加载器通常会带来自己的header 作为GL.hglext.h等的替代品,而典型的 GL 加载器(如 GLEW)只需将每个 GL 函数重新定义为宏,如下所示:

#define glFooFunc() __myloader_FooFunc

where __myloader_FooFunc is just a function pointer which must be initialized with some function provided by your loader (like glewInit ).其中__myloader_FooFunc只是一个function 指针,它必须使用加载程序提供的一些 function 进行初始化(如glewInit )。

Now this has a few effects: If you include the GL loader's header in some source file, the preprocessor will already replace all glSomething function names, and the linker will never see them.现在这有一些影响:如果您在某个源文件中包含 GL 加载程序的 header,预处理器将已经替换所有glSomething function 名称,而 Z3175B426046787EECE73773874 将永远不会看到它们。 But that is only true in that particular source file.但这仅在该特定源文件中是正确的。 If you have another source file without the loader header, the actual GL function names are used, and the linker will not find them.如果您有另一个没有加载程序 header 的源文件,则使用实际的 GL function 名称,而 linker 将找不到它们。

From your error messages like:从您的错误消息中,例如:

imgui_impl_opengl3.cpp.obj : error LNK2019: unresolved external symbol __imp_glBlendEquation referenced in function "void __cdecl ImGui_ImplOpenGL3_SetupRenderState(struct ImDrawData *,int,int,unsigned int)" (?ImGui_ImplOpenGL3_SetupRenderState@@YAXPEAUImDrawData@@HHI@Z)

it is easy to see that the function ImGui_ImplOpenGL3_SetupRenderState was not compiled with a GL loader, but used the GL function names directly.很容易看出 function ImGui_ImplOpenGL3_SetupRenderState没有使用 GL 加载器编译,而是直接使用了 GL function 名称。

Since ImGui supports OpenGL backends, it has already a way to deal with this, look at the official examples:由于 ImGui 支持 OpenGL 后端,它已经有办法处理这个,看官方的例子:

 // About Desktop OpenGL function loaders: // Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers. // Helper libraries are often used for this purpose, Here we are supporting a few common ones (gl3w, glew. glad), // You may use another loader/header of your choice (glext, glLoadGen. etc,). or chose to manually implement your own. #elif defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) #include <GL/gl3w.h> // Initialize with gl3wInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) #include <GL/glew.h> // Initialize with glewInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include <glad/glad.h> // Initialize with gladLoadGL() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2) #include <glad/gl.h> // Initialize with gladLoadGL(...) or gladLoaderLoadGL() [...]

So if you want to use ImGui with GLEW, you'll have to use IMGUI_IMPL_OPENGL_LOADER_GLEW因此,如果您想将 ImGui 与 GLEW 一起使用,则必须使用IMGUI_IMPL_OPENGL_LOADER_GLEW

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM