Loading... # Qt undefined reference to `__imp_gl' ## 背景 今天重构代码时候将 ```cpp class Renderer : protected QOpenGLFunctions { ... void procedure() { glGenTextures } } ``` 改成了 ```cpp static inline void foo() { glGenTextures } class Renderer : protected QOpenGLFunctions { ... void procedure() { foo() } } ``` 在macOS下正常编译,但是Windows下报错`undefined reference to `__imp_glGenTextures'` ## 原因分析 经过搜索,找到相关讨论 https://stackoverflow.com/questions/34929323/qt-opengl-error-imp-gl > **Since Qt 5.5, on Windows, by default, Qt does not link against libGL**, 简单来说,存在两个`glGenTextures`的方法,一个是全局函数,一个是`QOpenGLFuctions`的成员函数。调用全局函数在Windows下需要手动链接`libGL`,这也是之前在编写代码的时候,Clion一直提示`::glGenTextures`的原因。我们应该调用的是QOpenGLFuctions的成员函数。 最后修改:2022 年 04 月 21 日 © 允许规范转载 赞 0 如果觉得我的文章对你有用,请随意赞赏