wxGLCanvas error: invalid use of incomplete type 'class wxGLCanvas'问题解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012927281/article/details/85337538

今天在使用wxWidgets过程中遇到了这一奇怪的问题,明明包含了头文件,同时头文件也包括该class的声明,为什么报了这一错误,通过内容分析基本可以确定wxGLCanvas声明不正确,但是头文件的内容会声明不正确?

仔细分析了一下头文件发现,确实是wxGLCanvas没有包含,细节就在:glcanvas.h中。

#if wxUSE_GLCANVAS

这一句看似没有功能,其实才是核心所在。现在的问题就比较直接了,验证一下wxUSE_GLCANVAS的值即可。

其实第一个想法是直接定义wxUSE_GLCANVAS,有了这个定义,wxGLCanvas自然就包含在内了。

在编译命令中加入-DwxUSE_GLCANVAS,编译的结果也验证了我的想法:

/usr/local/lib/wx/include/gtk2-unicode-3.0/wx/setup.h:554:0: warning: "wxUSE_GLCANVAS" redefined
 #define wxUSE_GLCANVAS       0

现在在我的系统中wxUSE_GLCANVAS定义为0,所以wxGLCanvas也就没有include进来。现在问题比较简单了,就是使wxUSE_GLCANVAS为1即可。根据编译输出信息,研究一下setup.h中的相关内容。

// Setting wxUSE_GLCANVAS to 1 enables OpenGL support. You need to have OpenGL
// headers and libraries to be able to compile the library with wxUSE_GLCANVAS
// set to 1 and, under Windows, also to add opengl32.lib and glu32.lib to the
// list of libraries used to link your application (although this is done
// implicitly for Microsoft Visual C++ users).
//
// Default is 1 unless the compiler is known to ship without the necessary
// headers (Digital Mars) or the platform doesn't support OpenGL (Windows CE).
//
// Recommended setting: 1 if you intend to use OpenGL, can be safely set to 0
// otherwise.
#define wxUSE_GLCANVAS       1

源码中的第一句说的已经比较明确了,这一宏定义是用于使能OpenGL支持的。而我是先安装的wxWidgets后安装的OpenGL,所以解决这个问题就比较简单了,在当前环境下重新编译安装一下wxWidgets即可。

此处我使用的配置选项是

 ./configure --with-gtk --with-opengl --enable-unicode

在编译过程中遇到了can't find -lGL的问题,

参考以下文章解决,这篇文章写的非常清晰。can't find -lGL的解决方法

上述问题解决后,make、make install,至此wxWidgets的安装就完成了。

通过上述重新安装过程,codelite直接从命令行启动出现mismatch的问题也解决了,重新编译代码最开始的问题也得到解决。

以上。

猜你喜欢

转载自blog.csdn.net/u012927281/article/details/85337538
今日推荐