Problems setting up OpenGL SuperBible 5th Edition

So, I recently got OpenGL SuperBible and configured the directories on Code :: Blocks on freeglut and GLTools.h , but these #include statements will not work:

 #include <GLtools.h> #include <GLShaderManager.h> #include <iostream> #include <GL/glut.h> 

To install the directories, I looked at the Settings tab โ†’ Compiler and Debugger ... โ†’ Directory Search and added it under the Compiler tab (there is also the Compiler and Resource Compiler tabs):

 C:\CodeBlocks\SB5\Src\GLTools\include 

and

 C:\CodeBlocks\SB5\freeglut-2.6.0\include 

These are the errors I get:

 C:\CodeBlocks\SB5\freeglut-2.6.0\include\GL\freeglut_std.h|60|warning: "NOMINMAX" redefined| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\mingw32\bits\os_defines.h|46|warning: this is the location of the previous definition| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|225|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|226|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|227|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|228|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|229|error: 'GLAPI' does not name a type| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|230|error: 'GLAPI' does not name a type| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|231|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|232|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|233|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|234|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|235|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|236|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|237|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|238|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|239|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|240|error: expected constructor, destructor, or type conversion before 'const'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|241|error: expected constructor, destructor, or type conversion before 'const'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|242|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|243|error: expected constructor, destructor, or type conversion before 'const'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|244|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|245|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|246|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|247|error: 'GLAPI' does not name a type| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|248|error: 'GLAPI' does not name a type| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|249|error: 'GLAPI' does not name a type| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|250|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|251|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|252|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|253|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|254|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|255|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|256|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|257|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|258|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|259|error: 'GLAPI' does not name a type| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|260|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|261|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|262|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|263|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|264|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|265|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|266|error: 'GLAPI' does not name a type| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|267|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|268|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|269|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|270|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|271|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|272|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|273|error: expected constructor, destructor, or type conversion before 'void'| c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|274|error: expected constructor, destructor, or type conversion before 'void'| ||More errors follow but not being shown.| ||Edit the max errors limit in compiler options...| ||=== Build finished: 50 errors, 2 warnings ===| 

There seems to be some kind of conflict between the header files, although it occurs with errors in glu.h when I did not even include it.

Please, help! and thanks! =)

+4
source share
2 answers

I ran into the same problem as when trying to compile the Triangle example in SuperBible (5th Edition). I also like to use Code :: Blocks with MinGW. I do some research, and I think I managed to solve most of the problems.

The first thing to do is set up our environment correctly. We start by setting up libraries, freeglut and GLTools.

Before you begin, make sure you have the latest version of MinGW installed, with MSYS. Make sure you add c: / MinGW / bin to the path variable. Also get a good file extractor such as 7z that can unzip .tar and .gz files.

I will probably be too detailed, but for me it was not obvious until I examined them.

To install freeglut-2.6.0, the first thing we are going to do is build a static library from the source:

  • Go to the freeglut website and download the latest version (currently 2.6.0)

  • Create the c: / libs directory and unzip the freeglut package. You should get the directory c: /libs/freeglut-2.6.0.

  • Run MSYS (c: /MinGW/msys/1.0/msys.bat). You must be in your home directory (indicated by ~ after your user and host on the top line).

  • Type "cd / c / libs / freeglut-2.6.0 / src" and press [enter]. ~ Changes to / c / libs / freeglut -2.6.0 / src to indicate your current working directory.

  • Type "gcc -O2 -c -DFREEGLUT_STATIC * .c -I ../include" and press [enter]. What we are doing here calls the gcc compiler, instructing it to use O2 optimization, set the FREEGLUT_STATIC flag, and compile each source file in this directory into .o object files and look for headers in "../include". This means going one level (to / c / libs / freeglut-2.6.0) and looking for the / include directory there.

  • Type "ar rcs libfreeglut32_static.a * .o" and press enter. As far as I understand, ar is a utility that collects static libraries, archive files (.a). We tell him to create "libfreeglut32_static.a" from each object file (.o) that we just compiled in the previous step.

  • Create the / lib directory in / c / libs / freeglut-2.6.0. Then cut off the library we just created and paste it into this directory. The final location of the freeglut library should be "c: /libs/freeglut-2.6.0/lib/libfreeglut32_static.a".

Go to this site for more information on compiling freeglut using MinGW.

Before starting GLTools, make sure freeglut is working.

  • Open Code :: Blocks and close all open projects. Go to "Settings-> Compiler and Debugger" and open the "Search Directory" tab. In the compiler, add the directory "c: /libs/freeglut-2.6.0/include/". In Linker add "c: /libs/freeglut-2.6.0/lib/".

  • Create an empty project. Add test.cpp file. Add a single function int main (){return 0;} .

  • It should be built without problems.

  • Add #define FREEGLUT_STATIC and #include <GL/glut.h> .

  • Try compiling. It will not succeed.

  • Right-click on the project and go to "Build Options". Make sure that you edit the parameters for the entire project, and not for the purpose of debugging or release. Go to the Linker tab and add "freeglut32_static" to the link libraries.

  • Try compiling. It will not work again. The compiler will call an "undefined link to" errors "listing a bunch of functions. Copy the name of the first and find it on google. Go to the Microsoft search results (first or second result). It will describe the function and, more importantly, tell you in which library this function is located.

  • The library will be called "something.lib". Go to "Build Options" again and add "something" to the link libraries.

  • Try to compile again. He will fail again. If you bother checking, you will see that the first โ€œundefined linkโ€ has changed. Repeat 7 and 8 until it stops working. Additional libraries that you need to add in order to get freeglut working are "Winmm", "Gdi32" and "Opengl32".

  • Compile again. test.exe needs to be created. Hooray!

Well, now that we have freeglut running, it's time to break it down again. We are going to recreate the GLTools library first, as SB5 only distributes the .lib version.

  • There must be 4 main directories in the SB5 download; freeglut, linux, visualstudio and src. Log in to src. Copy the GLTools directory and paste it into the "c: / libs" folder.

  • Create the lib directory in GLTools. Now it should have three directories: / include, / src and / lib.

  • Raise MSYS again. Type "cd / c / libs / GLTools / src" and press [enter].

  • As with freeglut, we are going to capture all the tool code and link it to one library. Type "g ++ -c * .cpp -I ../include" and press [enter], then "ar rcs libGLTools.a * .o".

  • Cut the output, libGLTools.a, to "c: / libs / GLTools / lib".

  • We do the same for glew. Type "g ++ -c glew.c -I ../include" and then [enter]. Then "ar rcs libglew.a glew.o".

  • In Code :: Blocks, go back to "Settings-> Compiler and Debugger" and open the "Directory Directory" tab. In the compiler, add the directory "c: / libs / GLTools / include /". In Linker, add "c: / libs / GLTools / lib /".

  • I promised that we would break what we did before, right? Add #include <GLTools.h> to our test program and try to build a project. You should get a lot of "GLAPIs" that don't call type errors. This is because at some point (not sure where I am) the GLAPI is not defined. Or it is determined incorrectly.

Itโ€™s worth investigating if you have never worked with such libraries (I didnโ€™t, so this is a learning experience for me). When we include glut.h, if you open the header file, you will see that it simply includes freeglut_std.h. So you open this file and it has a bunch of preprocessor commands.

Run a GLAPI search in the document and we will find out that it does not define it here. However, it includes <GL/gl.h> and <GL/glu.h> . So open gl.h and search there.

Bingo! We can see several commands that work with our GLAPI definition. This is a bit confusing, but we're going to copy what the preprocessor usually does. So we have these lines:

 /* GLAPI, part 1 (use WINGDIAPI, if defined) */ #if defined(__WIN32__) && defined(WINGDIAPI) # define GLAPI WINGDIAPI #endif /* GLAPI, part 2 */ #if !defined(GLAPI) # if defined(_MSC_VER) /* Microsoft Visual C++ */ # define GLAPI __declspec(dllimport) # elif defined(__LCC__) && defined(__WIN32__) /* LCC-Win32 */ # define GLAPI __stdcall # else /* Others (eg MinGW, Cygwin, non-win32) */ # define GLAPI extern # endif #endif 

We can search freeglut_std.h and find out that WINGDIAPI is not defined. So, we skip the first block. The second block shows that the desired line #define GLAPI extern .

What seems to be happening is that one of the headers in GLTools messed up this definition for us. There is little to be done there, but try to figure out what the problem is.

GLTools doesn't say anything about GLAPI, but includes <windows.h> and <GL/glew.h> before <GL/gl.h> . glew.h defines GLAPI several times, but because the code does not have an identifier that makes it confused to determine if the code is entered or not. It is clear, however, that for our purposes, GLAPI must be defined as extern. So, we are going to make a quick hack in our test.cpp and define GLAPI as extern right before the command to enable.

 #include <GLTools.h> #define FREEGLUT_STATIC #define GLAPI extern #include <GL/glut.h> 

It will still be broken, but we should get the NEW output error! Therefore, we compile and ...

Yes. It compiled without errors. It should not have been. But then we do not call any functions in GLTools, so perhaps this is not so strange. We will push our luck and add a second include to triangle.ccp, #include <GLShaderManager.h> . And compile, and again no errors.

Well, that's why we are almost ready to build an example. Now we start filling out test.cpp with the contents of triangle.cpp and testing when it fails. I start by adding

 GLBatch triangleBatch; GLShaderManager shaderManager; 

outside the main one, and there we go, a couple of undefined links. I like it more. Therefore, we open the Build options (do not forget to specify the entire project, and not the goals of release or debugging) and add GLTools to the Link libraries. We do this, and now (as you would expect if you would pay attention to this), we get a bunch of undefined references to glew functions.

In and! So exciting. So now we add the glew library to the Build options. If you tied up glew at the end, we will learn something new. You must remember that when linking libraries, those who have their own dependencies must be linked in front of those on which they depend. It would be useful if we knew what they all depend on in advance, so draw a map or something else in the future.

So, we want to link freeglut, which depends on winmm, gdi32 and opengl32. We also want to use GLTools, which depends on glew and glew, which depends on opengl32. The binding order should be ... freeglut, GLTools, glew, winmm, gdi32 and opengl32. Let's see if this works.

Ha! It compiled without errors. Damn, I'm good (not really :().

So, now that we have set up the environment, I copied the rest of the Triangle.cpp file, saved, created and received no errors.

I tested these steps on two computers and they worked. I think the steps above should allow anyone with Code :: Blocks and MinGW to create tutorials in OpenGL SuperBible, 5th Edition.

+14
source

This problem was fought for a couple of days, checking the code from several lessons. I suppose because most of them are made with Visual C / C ++ in mind, but I really wanted to use C :: B with MinGW for this task.

I think I found an easy solution to this problem:

1) If you still could not correctly install freeglut-2.6.0 for MinGW, try to get it here:

http://files.transmissionzero.co.uk/software/development/GLUT/freeglut-MinGW.zip

Unzip and make the .h and .a files available for your project. Save the .dll for later versions.

2) Add these two definitions before you include glut.h

 #define GLUT_DISABLE_ATEXIT_HACK #define GLAPI extern #include <GL/glut.h> 

3) Compile your project

4) Before starting the executable file, copy the freeglut.dll file to its directory

5) Happy Glack (finally!)

0
source

Source: https://habr.com/ru/post/1347400/


All Articles