I have created this header (.h file) and C++ file (.cpp) to show rotating object
the header file (CGfxOpenGL.h) :
class CGfxOpenGL
{
private:
int m_windowWidth;
int m_windowHeight;
float m_angle;
public:
CGfxOpenGL();
virtual ~CGfxOpenGL();
bool Init();
bool Shutdown();
void SetupProjection(int width, int height);
void Prepare(float dt);
void Render();
};
The cpp file (learnopengl2triangleglew.cpp)
#include <GL/gl.h>
#include <GL/glu.h>
#include <math.h>
#include "CGfxOpenGL.h"
#include <iostream>
CGfxOpenGL::CGfxOpenGL()
{
}
CGfxOpenGL::~CGfxOpenGL()
{
}
bool CGfxOpenGL::Init()
{
// clear to black background
glClearColor(0.0, 0.0, 0.0, 0.0);
m_angle = 0.0f;
return true;
}
bool CGfxOpenGL::Shutdown()
{
return true;
}
void CGfxOpenGL::SetupProjection(int width, int height)
{
if (height == 0)
{
height = 1;
}
glViewport(0, 0, width, height); // reset the viewport to new dimensions
glMatrixMode(GL_PROJECTION); // set projection matrix current matrix
glLoadIdentity(); // reset projection matrix
// calculate aspect ratio
gluPerspective(52.0f,(GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
m_windowWidth = width;
m_windowHeight = height;
}
void CGfxOpenGL::Prepare(float dt)
{
m_angle += 0.1f;
}
void CGfxOpenGL::Render()
{
// clear screen and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// move back 5 units and rotate about all 3 axes
glTranslate(0.0, 0.0, -5.0f);
glRotatef(m_angle, 1.0f, 0.0f, 0.0f);
glRotatef(m_angle, 0.0f, 1.0f, 0.0f);
glRotatef(m_angle, 0.0f, 0.0f, 1.0f);
// lime greenish color
glColor3f(0.7f, 1.0f, 0.3f);
// draw the triangle such that the rotation point is in the center
glBegin(GL_TRIANGLES);
glVertex3f(1.0f, -1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
}
the problem is after I type this in terminal:
g++ -o test learnopengl2triangleglew.cpp -lGL -lGLU -ldl
I get: undefined reference to 'main'
My conditions:
- I have build and install GL. I have GL/gl.h and GL/glu.h as well.
- I have math.h from glm too.
- I am using Linux OS.
How should I solve this?
P.S. It is an example file from Beginning OpenGL Game Programming Book.
this is the screenshot of the error (I fix the gluPerspective by adding -lGLU

It seems that you're trying to compile a C++ program, but there is no main function in your code, which is the entry point of a C++ program. Additionally, you're using functions like gluPerspective from the OpenGL utility library (GLU), but you haven't linked against it.
First Add a main function
Link the OpenGL Utility Library (GLU):
Set the values for the width and height
Remember, you will need a loop for rendering and updating also you may need to handle user input. Additionally make sure that you have initialized an OpenGL context before using any OpenGL functions.