OpenGL SuperBible first example not compiling

Hi

I use Eclipse and Linux.
I compiled the example project with cmake and make. This works great and the output files are working, too. So I have all requirements to get it working.

If I try to create a own Project, it doesn’t work.

This is what I did:

  • Create new C++ Project
  • In Project Properties I added GL, glut and GLU to the linker
  • I added the include dir from the examples project of the book (with the sb7.h)
  • I created a new c++ file:
#include "sb7.h"

class my_application : public sb7::application
{
public:
	void render(double currentTime)
	{
		static const GLfloat red[] = {1.0f, 0.0f, 0.0f, 1.0f };
		glClearBufferfv(GL_COLOR, 0, red);
	}
};

DECLARE_MAIN(my_application);

this is the first example in the book.

But now there is an error:
DECLARE_MAIN could not be resolved.
I don’t understand it, because it is in the sb7 header file…

for those, who don’t know this book:
you can find the example project with the sb7 header here:
https://github.com/openglsuperbible/sb7code

I think there is only something little missing, but I don’t know what it is. Can anyone help me, please?

Edit:
I now changed it to this:


#ifndef _LINUX
#define _LINUX
#endif

#include "sb7.h"

class my_application : public sb7::application
{
public:
	void render(double currentTime)
	{
		static const GLfloat red[] = {1.0f, 0.0f, 0.0f, 1.0f };
		glClearBufferfv(GL_COLOR, 0, red);
	}
};

int main(int argc, const char ** argv)
{
	my_application *app = new my_application;
    app->run(app);
    delete app;
    return 0;
}

with this I first get no error. But when I compile it, I get this:
test.cpp:13: undefined reference to `gl3wClearBufferfv’

line 13 is: glClearBufferfv(GL_COLOR, 0, red);
What does that mean?

1 Like

I had the same issue but the Edit: code worked for me :slight_smile:

Hi, remember what is written in the book:

The application framework is brought into your application by including sb7.h in your source code. This is a C++ header file that defines a namespace called sb7 that includes the declaration of an application class, sb7::application, from which we can derive our examples. The framework also includes a number of utility functions and a …

Taking into consideration that the sole use of the sb7.h header brought to your application a whole framework, you have to take into account that your example will not compile and run just including the header file and running g++ or your compiler command. It will work if you set up all the requirements of the framework (environmental variables, includes, and so on), that are described and setted in the CMakeLists.txt file.*

Note: Did you compile and run the whole set of examples that are shipped along with the book? you need to do that first.

Comming back with the first example described in the book, edit the CMakeList.txt file and add your first example project.

.
.
set(EXAMPLES
  firstexample
  alienrain
  basicfbo
  bindlesstex
  blendmatrix
  blinnphong
  bumpmapping
.
.

That snippet includes all the projects that will be compiled, and in that array is where you need to put the name of your first example (ie: firstexample). So, go and create a new directory with the name of your cpp file inside the src directory, and put your cpp file inside that directory. Follow the steps described in HOWTOBUILD.txt file, and it is done.