ITADN

`wglGetProcAddress` in `wgl.c` introduces a dependency on `OpenGL32.lib`

#534Openbellenot 创建于 2026-02-19
B
bellenotcommented
Hello, When generating `wgl.c`, there is this part of the code: ``` static GLADapiproc glad_wgl_get_proc(void *vuserptr, const char* name) { GLAD_UNUSED(vuserptr); return GLAD_GNUC_EXTENSION (GLADapiproc) wglGetProcAddress(name); } ``` Where using `wglGetProcAddress` introduces a direct dependency on `OpenGL32.lib` (i.e. one needs to links against it) I think something similar to the following code should be generated: ``` typedef void* (GLAD_API_PTR *GLADwglprocaddrfunc)(const char*); static GLADapiproc glad_wgl_get_proc(void *vuserptr, const char* name) { GLAD_UNUSED(vuserptr); GLADapiproc result = NULL; void *handle = (void*) LoadLibraryA("opengl32.dll"); GLADwglprocaddrfunc wgl_get_proc_address_ptr = (GLADwglprocaddrfunc) GetProcAddress((HMODULE) handle, "wglGetProcAddress"); if (wgl_get_proc_address_ptr != NULL) result = GLAD_GNUC_EXTENSION (GLADapiproc) wgl_get_proc_address_ptr(name); return result; } ``` I tested it and it works just fine. Then we (the ROOT project at CERN) can get rid of a special case for Windows where we have to link against `OpenGL32.lib` only because of that function call. Thanks in advance! Cheers, Bertrand.
2 条评论