Compiling opengl code using gcc through the command line

Started by
52 comments, last by 4mad3u5 10 years, 1 month ago

Hi, I do not want to use visual studio express because microsoft just wants your cc and they are trying to kill opengl so there is no point to use their compiler. So I want to use Dev C++ gcc from the command line to compile code instead of vs. I have three books that I am using to learn opengl: opengl programming guide, opengl supper bible 5, and interactive computer graphics. I have been able to get code to compile with vs but we are not able to compile using Dev C++ gcc. I have been working with two professors everyday for the last three months and we can't figure this out.

The first program that I am working with is from SB5. If you want the source code and include folders that I am using you can get them from the supper bible site: www.openglsuperbible.com/previous-editions/ 5th edition I am in chapter 2 triangle. I expect the command line to be something like this:

g++ -IF:\school\csci\opengl\SB5\Src\GLTools\include -IF:\school\csci\opengl\SB5\freeglut-2.6.0\include Triangle.cpp libglew32.a libfreeglut.a

I have put libglew32.a and libfreeglut.a in my working directory, and I still get a bunch of errors referencing lib files and if I take out the libglew32.a and libfreeglut.a from my command line I get the same error messages so it is for sure not linking to the correct libraries, so I have no idea what to do. Here is the code I am working with:


// Triangle.cpp
// Our first OpenGL program that will just draw a triangle on the screen.

#include <GLTools.h> // OpenGL toolkit
#include <GLShaderManager.h> // Shader Manager Class

#ifdef __APPLE__
#include <glut/glut.h> // OS X version of GLUT
#else
#define FREEGLUT_STATIC
#include <GL/glut.h> // Windows FreeGlut equivalent
#endif

GLBatch triangleBatch;
GLShaderManager shaderManager;

///////////////////////////////////////////////////////////////////////////////
// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
}


///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
// Blue background
glClearColor(0.0f, 0.0f, 1.0f, 1.0f );

shaderManager.InitializeStockShaders();

// Load up a triangle
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f };

triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}



///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
triangleBatch.Draw();

// Perform the buffer swap to display back buffer
glutSwapBuffers();
}


///////////////////////////////////////////////////////////////////////////////
// Main entry point for GLUT based programs
int main(int argc, char* argv[])
{
gltSetWorkingDirectory(argv[0]);

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800, 600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);

GLenum err = glewInit();
if (GLEW_OK != err) {
fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
return 1;
}

SetupRC();

glutMainLoop();
return 0;
}



Here is what happens right after I hit enter on the command line:

In file included from F:/school/csci/opengl/SB5/freeglut-2.6.0/include/GL/freeglut_std.h:121,
from F:/school/csci/opengl/SB5/freeglut-2.6.0/include/GL/glut.h:17,
from Triangle.cpp:11:
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:225: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:225: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:226: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:226: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:227: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:227: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:228: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:228: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:229: error: `GLAPI' does not name a type
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:230: error: `GLAPI' does not name a type
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:231: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:231: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:232: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:232: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:233: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:233: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:234: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:234: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:235: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:235: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:236: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:236: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:237: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:237: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:238: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:238: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:239: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:239: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:240: error: expected constructor, destructor, or type conversion b
efore "const"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:240: error: expected `,' or `;' before "const"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:241: error: expected constructor, destructor, or type conversion b
efore "const"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:241: error: expected `,' or `;' before "const"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:242: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:242: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:243: error: expected constructor, destructor, or type conversion b
efore "const"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:243: error: expected `,' or `;' before "const"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:244: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:244: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:245: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:245: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:246: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:246: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:247: error: `GLAPI' does not name a type
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:248: error: `GLAPI' does not name a type
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:249: error: `GLAPI' does not name a type
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:250: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:250: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:251: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:251: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:252: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:252: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:253: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:253: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:254: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:254: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:255: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:255: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:256: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:256: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:257: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:257: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:258: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:258: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:259: error: `GLAPI' does not name a type
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:260: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:260: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:261: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:261: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:262: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:262: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:263: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:263: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:264: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:264: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:265: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:265: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:266: error: `GLAPI' does not name a type
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:267: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:267: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:268: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:268: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:269: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:269: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:270: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:270: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:271: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:271: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:272: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:272: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:273: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:273: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:274: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:274: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:275: error: expected constructor, destructor, or type conversion b
efore "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:275: error: expected `,' or `;' before "void"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:276: error: `GLAPI' does not name a type
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glu.h:277: error: `GLAPI' does not name a type

Advertisement

There are plenty of good, valid reasons not to use MSVC. What you wrote up there is not among them.

That said, Dev-C++ is the most useless replacement you could pick. It's ancient, unmaintained and full of bugs. There are some forks of Dev-C++ which are still actively developed but other tools have several years of headstart on them.

Before using Dev-C++ I would rather use a current gcc without any extra help, just a text editor and the command line. gcc 3.4.2 (which is what you are using) is ten years old. For all intends and purposes it is completely useless to get something done nowadays. Whatever problems you have probably originate in obsolete tools.

Investigate Code::Blocks or QtCreator if you want a modern, free IDE. Several other options exist.

Actually microsoft wanting to kill opengl so there is no point in using their compiler is a pretty good reason.

a

Its my instructors that are telling me to use Dev C++

Just because they are in a position to tell students what the world looks like, doesn't mean it's true. :)

For pure C++: Check out TDM-GCC project. It has an up to date GCC. Also mingw64, mingw-builds and so on.

For linux you only need to install g++.

http://tdm-gcc.tdragon.net/

You can also check out Qt: http://qt-project.org/

I don't particularly like Qts version of C++, but everything about Qt is easy, well documented, and "it just works." Which is more than you can say for absolutely everything else on particularly Linux.

If you are not fond of C++, consider using Python or Java.

You also have some (future) options in game development with HTML5 and all the almost-there stuff that changes every now and then.

There is also nothing wrong with developing for Microsoft only, considering most people game on windows. Just be aware that programming multiplatform from the beginning really isn't that hard. The longer you go programming with microsofts C++ ABI the longer it will take you to make the correct changes to have your projects work on other systems.

I would consider it an investment in your own future to just stay multiplatform, and also "stay current." (By using the latest versions of absolutely everything)

thank you very much, nobody wants to help me and all I am getting is people trying to insult me

Maybe try http://codelite.org/ , I've used it to build OpenGL apps on Linux.

You get errors in included headers, so I would start by building a simpler app in whatever compiler you attempt to use, as in printf("Hello World"); return 0;

Then when that works add one line or function at a time until it doesn't work, and you at least know where it goes wrong.

Who insulted you? Could you quote their insult? mellow.png

They are helping you. They are telling you:

A) Dev C++ is outdated, buggy, unsupported, and no longer used by the vast majority of programmers.

B) The claims against Microsoft are mostly overstated. And this is a community that is highly geeky and heavily uses Linux as well as Microsoft software.

C) There ARE valid reasons for not wanting to use Microsoft's compiler. OpenGL support isn't one of them. Visual C++ can compile OpenGL just fine.

D) Microsoft's compiler and IDE is generally considered the best that is currently available, though the opensource alternatives are rapidly gaining ground.

E) I personally use GCC myself, and even I avoid the Dev C++ IDE as junk. I now prefer the opensource Qt Creator IDE, which @Kaptein already linked to.

When people tell me something I don't want to hear, they are trying to help me. It's sometimes too easy for me to mistake "corrections" for "insults". wink.png

Servant of the Lord I have posted this question on 4 different sites.

I know how to tell the difference between helping and insulting

This topic is closed to new replies.

Advertisement