Problem with glu / confusion with void, int main


I’m new to this forum and I’m learning C++ and OpenGL. I’m using Windows XP, texteditor, latest GCC and Gnu Make versions. While I’ve got basic knowledge of C++ (or even less), OpenGL is completely new to me.
I’m following this tutorial (, which is, by the way, very good.

But I’m puzzled about two things:

  1. In the tutorial the main function is written as void:

void main(int argc, char **argv) {

But my gcc compiler gives errors here: “‘main’ must return ‘int’” and “return type for ‘main’ changed to ‘int’”.

I then changed the function into int:

int main(int argc, char **argv) {

Why can’t I have void there?

  1. If I compile my code with that changed line I get zero errors. But when I try to run the compiled .exe file I get a windows error:
    The application failed to initialize properly - 0xc0000005

When I comment the lines




the error doesn’t occur anymore, but the window has bugs while resizing. Is this error a problem with the glu library?
I’m using the following makefile:

# A simple Makefile
# C++ using GNU Make and GCC
# opengl32.lib glut32.lib glu32.lib odbc32.lib odbccp32.lib

myprogram.exe : myfile.cpp
	gcc myfile.cpp -Wall -lopengl -lglu -lglut32

this is my code:

/* hallo.c */

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <GLUT/glut.h>

using namespace std;

void renderScene(void) {
void changeSize(int w, int h) {

	// Prevent a divide by zero, when window is too short
	// (you cant make a window of zero width).
	if(h == 0)
		h = 1;

	float ratio = 1.0* w / h;

	// Reset the coordinate system before modifying
	// Set the viewport to be the entire window
	glViewport(0, 0, w, h);

	// Set the correct perspective.

int main(int argc, char **argv) {
	glutInit(&argc, argv);
	glutCreateWindow("3D Tech- GLUT Tutorial");


I’d appreciate any help from you.


I haven’t used gcc in a long time but either you get this error by default or it is because of your -Wall option. I believe it is considered a better practice to explicitly return an int since a user can write a script (e.g. a .bat file) that calls your program and checks for error codes. I even recall a corny saying: “friends don’t let friends void main.” BTW Visual C++ 2008 Express Edition is free and may be easier to use depending on your preferences, not that I want to steer you away from using makefiles, etc, since that is a great skill to have.


hi pjcozzi

Thank you for your answer. Since “int main” is better practice anyways, I’ll avoid “void” main in future.

No, it’s not because of that. I removed it in the makefile and there’s still the same error. It seems to be forbidden in C and C++.

I have Visual C++ Express edition, I also have Dev C++, I tried them out. My problem with IDEs is that I lose the overview. With gcc and text editor you know what you have. No hidden buttons and options in the IDE you might overlook or anything like that. In addition, I want to be OS independent.


I use gcc on both Linux and Windows. It is a great tool for just the reasons you mentioned and more :slight_smile:

Definitely avoid the use of “void main” since it is not ANSI standard coding style.

What compile tools are you using – cygwin or mingw/msys?

Does the change as follows work?

-lopengl32 -lglu32 -lGLUT32

Those are the link libraries I have to use with mingw/msys commandline environment in windows. Note on linux just “-lglut” is required.

P.S. If you ever want to be truly cross platform and share code with others. A simple consistent change will make that possible

#ifdef WINDOWS
#include <windows.h>

and glut.h by standard convention goes in GL/ folder
#include <GL/glut.h>

With those two coding style changes your code will compile as-is on windows and Linux alike. You don’t need to do this but I just point it out because it is a minor change that allows you to be cross platform in the long run. Also similar changes may be needed to compile demos from windows/linux/glut code you may run across in the net as you learn openGL. Even though glut is cross platform by design some coders put extraneous OS specific code in that breaks cross platform ability needlessly – the simple #IFDEF undoes that.

Oh, sorry that I didn’t mention that. I didn’t know there’s anything else than MinGW, I’ve got that one.

You are right! It’s working! I don’t know why and how it finds the “opengl32” and “glu32” library. It seems that they already came with MinGW, but the files are named “libopengl32.a” and “libglu32.a”. Thank you very much.

Of course I’ll take your advice and I’ll use these lines for future programs.


Glad that helped. I think they did come with your mingw/msys installation. Note that when you specify -lFOO gcc automatically searches its library path and uses the first found file named libFOO.a ie by adding the prefix “lib” and postfix “.a”.

Not that you need it now but a nice reference to bookmark is GCC library path. It is a nice reference that I go back to sometimes when I install new libraries etc.

Thank you for that link. I’ve read pieces of these informations all over the internet and it’s really nice to see them collected on one page.
I’ve already tried out some custom library directories and it actually worked. Cool stuff.