Compilation errors in a cpp file

Hi there. I mostly do and code in Gfortran in Ubuntu 13.04 however when a cpp file comes my way I try to compile and use it. I do not do any coding in cpp myself. My area is numerical analysis.

Today I downloaded this file

sphere_voronoi_display_opengl.cpp

from what seems to be a reputable website:

http://people.sc.fsu.edu/~jburkardt/cpp_src/sphere_voronoi_display_opengl/sphere_voronoi_display_opengl.html

After commenting out one include:

//# include <GLUT/glut.h>

which pertains MAC X OS I tried to compile it with g++ command.

I got a shocking number of errors. They are mostly of two types:

1
2
3
  sphere_voronoi_display_opengl.cpp:381:5: error: ‘t’ was not declared in this scope
     t = gen_color[0+gen*3];
     ^


or:

1
2
3
sphere_voronoi_display_opengl.cpp:41:10: error: ‘GLfloat’ does not name a type
   static GLfloat *gen_color;
          ^


I guess my question is: what kind of code is it? Is is something that was written in lieu of a different compiler or it is just an incompetent job?

My second question is: Shall I ry to correct all these numerous errors or simply throw this code away?

Thanks, - a.
Do you have OpenGL installed? The code uses it, so if you only download the cpp file and don't have OpenGL, the code won't compile.

I'm guessing that if you don't have Mac OS X, you'd comment out that one header and un-comment out the others.

1
2
3
4
5
6
7
//
//  This is the include statement I need for Mac OS X.
//
# include <GLUT/glut.h>

//# include <GL/glut.h>
//# include <GL/freeglut.h> 
Thank you for the pointer but I have to figure out how to install openGL. Ubuntu command sudo apt-get install opengl did not work.
You should be able to find a copy of glut for your OS here:
https://www.opengl.org/resources/libraries/glut/glut_downloads.php
Websearch for "ubuntu opengl glut dev". The packages are most likely in Ubuntu base repositories.
The package is called freeglut3-dev
http://packages.ubuntu.com/precise/freeglut3-dev
I would still recommend the other link in the spirit of promoting the source.
Thank you guys. The support in this forum is incredible. I just tried it and it said that I already have the newest version. Now, how do I use it? It does not seem to be a separate command like gnuplot
Last edited on
Use #include <GL/glut.h>
Build the program with
$ g++ sphere_voronoi_display_opengl.cpp -l{GL,GLU,glut} -o this_would_be_the_program_name.bin
Last edited on
Good morning. I am back here. I slightly lost control of this thread because I am in multitasking now because of circumstances. I think last night I installed openGL but not quite sure if this is the case. So, I found this command on the Web:

[code]alex@alex-..../SPHERE-DESIGN$ glxinfo | grep "OpenGL version"
libGL error: failed to open drm device: Permission denied
libGL error: failed to load driver: r600
OpenGL version string: 2.1 Mesa 10.1.3 [/code"

I don't really understand the output. Does it say that I have installed openGL? I am an application programmer and I have a lot on my plate in there now, so I hope you will excuse me for asking stupid questions.

You guys are wonderful!!!

Thanks, - A.
ne555, I just did what you said. I reactivated the include statement and ran this command:

g++ sphere_voronoi_display_opengl.cpp -l{GL,GLU,glut} -o a.out

IT COMPILED and it WORKS!!!

Thank you very much. - A.
I just marked this thread as solved but I do have a question. Aside from a cpp file I also have an sh file with the same name but a different extension, a script that is supposed to be used to run the cpp file. What shall I do about it? I read on the web that sh files should not be really used. Is it correct?
a *.sh contains commands to be interpreted by a shell (by instance, bash)
In your particular case, it contained the build commands for the .cpp file. (it was configured for OS X, you needed to comment a line).

> I read on the web that sh files should not be really used. Is it correct?
analyse the rationale.
if the source is trustworthy, I don't see a problem (I want my /usr back)
sh:
commands to compile the source code.


You did compile the program with a command (A).
The script has a command (B) to compile the program.

Do the A and B resemble each other in any way?

(It is actually possible that your A suits better your environment than the B.)


Shell scripts at large are very useful. A lot under the hood of Ubuntu is scripts. Scripts are not good or evil.


There are multiple utilities that can check what a system has and then generate as appropriate compilation commands for a program as possible. Such are used with multi-file programs that have to compile on GNU/Linux, OS X, Windows, Android, etc conveniently.


You, as a regular user apparently lack permission to access that "drm" device (the glxinfo attempts to do that).
Mesa is a software implementation of OpenGL.
The drivers of your GPU may support hardware-based implementation OpenGL.


@kevinkjt2000:
The Ubuntu ought to have package management. The manager keeps track of which packages have been installed (enabling 'uninstall' option), and may resolve dependencies and conflicts too. The management prefers packages that have been packaged for the system (i.e. have metadata about the package). Plain vanilla upstream source might be "unmanageable"; rogue files that the manager has no knowledge of. The managed system may also have special modifications in other packages which a source install will not anticipate. Furthermore, when a managed package is updated, all dependent packages have to comply, but nothing will know to check the source installs.

Mixing package management and source installs is like both you and your wife putting clothes into your cabinet; one or the other is bound to wonder why things are not "in proper order and place".
Topic archived. No new replies allowed.