我想我已经被这种问题逼疯了。我正在使用带有 qt5.6.0 (msvc2015_64) 的 visual studio 2015 社区来制作 QOpenglWidget 来演示使用 OpenCL 的设备计算的结果。
现在我盲目地使用函数“wglGetCurrentContext”和“wglGetCurrentDC”创建上下文,错误是:
“LNK2019 未解析的外部符号 _imp_wglGetCurrentContext 在函数中引用”protected: void _cdecl VolRenGL::createCLContext(int,char const* )“(?createCLContext@VolRenGL@IEAAXHPEAPEBD@Z)” “LNK2019 未解析的外部符号 _imp_wglGetCurrentDC 在函数中引用, protected :void _cdecl VolRenGL::createCLContext(int,char const *)”(?createCLContext@VolRenGL@@IEAAXHPEAPEBD@Z)”
相关代码:
cl_context_properties props[] =
{
CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
CL_CONTEXT_PLATFORM, (cl_context_properties)cpPlatform,
0
};
cxGPUContext = clCreateContext(props, 1, &cdDevices[uiDeviceUsed], NULL, NULL, &err);
最佳答案
愚蠢的问题,但是您是否将您的 程序与opengl32.lib/dll
链接起来?在 Windows 中,链接到 DLL 的符号不会“泄漏”,因此您必须链接到正确的库。 Qt 通过还提供一个 OpenGL 加载器隐藏了这个问题,因此如果您编写一个完全惯用的 Qt OpenGL 程序,您可以这样做而无需实际显式链接到 opengl32.lib/dll
关于c++ - wglGetCurrentDC 未解析的外部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38820643/