0

I just tested the code in chapter 1 (OpenGL 4.0 Shading Language Cookbook)

I have installed Qt5, qmake -tp vc chapter01.pro then open it in vs2010.

Built and got many errors like:

1>D:\APP\Qt5\5.0.0\msvc2010\include\GLES2/gl2.h(38): error C2371: 'GLintptr' : redefinition; different basic types
1>          D:\OpenGL\glew-1.5.4\include\GL/glew.h(1615) : see declaration of 'GLintptr'
1>D:\APP\Qt5\5.0.0\msvc2010\include\GLES2/gl2.h(39): error C2371: 'GLsizeiptr' : redefinition; different basic types
1>          D:\OpenGL\glew-1.5.4\include\GL/glew.h(1614) : see declaration of 'GLsizeiptr'
1>D:\APP\Qt5\5.0.0\msvc2010\include\GLES2/gl2.h(96): warning C4005: 'GL_BLEND_EQUATION_RGB' : macro redefinition
1>          D:\OpenGL\glew-1.5.4\include\GL/glew.h(1666) : see previous definition of 'GL_BLEND_EQUATION_RGB'
1>D:\APP\Qt5\5.0.0\msvc2010\include\GLES2/gl2.h(474): error C2365: '__glewActiveTexture' : redefinition; previous definition was 'data variable'
1>          D:\OpenGL\glew-1.5.4\include\GL/glew.h(12027) : see declaration of '__glewActiveTexture'
1>D:\APP\Qt5\5.0.0\msvc2010\include\GLES2/gl2.h(475): error C2365: '__glewAttachShader' : redefinition; previous definition was 'data variable'

How to solve these problems? (The code link is here)

lightrek
  • 951
  • 3
  • 14
  • 30

2 Answers2

2

Short answer: only include GLEW's header file, and don't include any OpenGL headers.

Explanation: GLEW's header file effectively includes everything in the OpenGL header files (I've never tried with GLES, but I suspect it's the same), redefining all of the OpenGL entry points through C preprocessor macros. This is why you're seeing the multiply-defined symbols and types. Additional information can be found here.

Community
  • 1
  • 1
radical7
  • 8,957
  • 3
  • 24
  • 33
  • Thanks for your help. However, I didn't explicitly include gl2.h in this project. Second, I commented out all OpenGL headers and these errors still exist. Why? – lightrek Feb 06 '13 at 16:01
  • 2
    From your post, it looks like Qt is including gl2.h for you. If you haven't tried this already: try including glew.h before any of your other headers. Based on this [post](http://qt-project.org/forums/viewthread/14446), that seems like it might help. – radical7 Feb 06 '13 at 16:05
  • This code comes from the book and I haven't changed anything. Yes, the glew.h is before other headers already. Thanks – lightrek Feb 06 '13 at 16:11
1

Not a best answer for sure, but I've just checked the book.

It seems that book is outdated when you get to Qt's version:

For example, in recent versions of Qt (at least version 4.7)

So, for the sake of easy reading the book, you may consider to downgrade your Qt to 4.x (4.8, for example) family, as there may be a lot of changes in the OpenGl requirements, especially if Qt build you are using is built with different OpenGl libraries.

Another solution is to use updated source code which doesn't require Qt at all:

This is the example programs from the OpenGL 4.0 Shading Language Cookbook, by David Wolff. The source code has been updated to work with MS Visual Studio, and no longer requires Qt.

Nemanja Boric
  • 21,627
  • 6
  • 67
  • 91