LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   g++ compiler (https://www.linuxquestions.org/questions/programming-9/g-compiler-170077/)

hylke 04-14-2004 11:40 AM

g++ compiler
 
Hello
I use kDevelop to compile my GLUT source codes.But i dont like to make all those projects with all those files.I want to compile my GLUT using g++.
In my linker options from my kDevelop i click on the libraries: X11, Xext and Math.

Then i add -lglut -lGLU -lGL -lXi -lXmu to Additional Libraries.

So what do i need to type on a shell to compile my GLUT c plus plus file?
thanx Hylke

aluser 04-14-2004 12:44 PM

my guess would be

Code:

g++ -o myprog myprog.cpp -L/usr/X11R6/lib -lglut -lGLU -lGL -lXi -lXmu -lX11 -lXext -lm
This should really be put into a Makefile, assuming that it works at all -- like I said, it's a guess :)

btw, you might try -lMath instead of -lm

hylke 04-14-2004 01:17 PM

What do u mean with putting it in a makefile?
I typed g++ -o myprog myprog.cpp -L/usr/X11R6/lib -lglut -lGLU -lGL -lXi -lXmu -lX11 -lXext -lm and g++ -o myprog myprog.cpp -L/usr/X11R6/lib -lglut -lGLU -lGL -lXi -lXmu -lX11 -lXext -lMath in a command line but both didn't work.

deiussum 04-14-2004 03:05 PM

Maybe you could define "didn't work" a little bit better. Like with actual error output. We can't very well tell you how to fix it if you don't tell us what error you got.

Edit: Also, you should read up on Makefiles a bit. They will make your life easier. Do a Google search, and I bet you will find tons of information explaining them.

hylke 04-15-2004 12:34 PM

My errors:
Quote:

[hylke@DONKER testgameengine]$ g++ -o myprog main.cpp -L/usr/X11R6/lib -lglut -lGLU -lGL -lXi -lXmu -lX11 -lXext -lm
/home/hylke/tmp/ccnJVzhY.o(.text+0x3d): In function `main':
: undefined reference to `GameEngine::GameEngine[in-charge](int, int, bool, int, int, int)'
/home/hylke/tmp/ccnJVzhY.o(.text+0x86): In function `main':
: undefined reference to `GameEngine::GameStart()'
/home/hylke/tmp/ccnJVzhY.o(.text+0x38e): In function `Render()':
: undefined reference to `GameEngine::DrawText(char*, float, float)'
/home/hylke/tmp/ccnJVzhY.o(.text+0x3ad): In function `Render()':
: undefined reference to `GameEngine::DrawText(char*, float, float)'
/home/hylke/tmp/ccnJVzhY.o(.text+0x3cc): In function `Render()':
: undefined reference to `GameEngine::DrawText(char*, float, float)'
/home/hylke/tmp/ccnJVzhY.o(.text+0x3eb): In function `Render()':
: undefined reference to `GameEngine::DrawText(char*, float, float)'
/home/hylke/tmp/ccnJVzhY.o(.text+0x667): In function `Render()':
: undefined reference to `GameEngine::DrawText(char*, float, float)'
/home/hylke/tmp/ccnJVzhY.o(.text+0x686): more undefined references to `GameEngine::DrawText(char*, float, float)' follow
/home/hylke/tmp/ccnJVzhY.o(.text+0x921): In function `End()':
: undefined reference to `GameEngine::~GameEngine [in-charge]()'
collect2: ld returned 1 exit status
EDIT: disable smilies.

deiussum 04-15-2004 01:07 PM

It appears you aren't including the source for your GameEngine class. Is that in main.cpp, or a separate .cpp file? If it's in a separate .cpp file, you will have to include that in your list like so:

g++ -o myprog main.cpp GameEngine.cpp -L/usr/X11R6/lib -lglut -lGLU -lGL -lXi -lXmu -lX11 -lXext -lm

hylke 04-15-2004 01:24 PM

When i did that i got the following errors:
Quote:

[hylke@DONKER testgameengine]$ g++ -o myprog main.cpp GameEngine.cpp -L/usr/X11R6/lib -lglut -lGLU -lGL -lXi -lXmu -lX11 -lXext -lm
GameEngine.cpp:1:24: GameEngine.h: No such file or directory
GameEngine.cpp:3: error: syntax error before `::' token
GameEngine.cpp:6: error: ISO C++ forbids declaration of `m_iWidth' with no type
GameEngine.cpp:6: error: `iWidth' was not declared in this scope
GameEngine.cpp:7: error: ISO C++ forbids declaration of `m_iGridX' with no type
GameEngine.cpp:7: error: `GridX' was not declared in this scope
GameEngine.cpp:8: error: ISO C++ forbids declaration of `m_iGridY' with no type
GameEngine.cpp:8: error: `GridY' was not declared in this scope
GameEngine.cpp:9: error: ISO C++ forbids declaration of `m_iGridZ' with no type
GameEngine.cpp:9: error: `GridZ' was not declared in this scope
GameEngine.cpp:10: error: ISO C++ forbids declaration of `bFullscreen' with no type
GameEngine.cpp:10: error: `fullscreen' was not declared in this scope
GameEngine.cpp:11: error: syntax error before `}' token
GameEngine.cpp:13: error: syntax error before `::' token
GameEngine.cpp:16: error: ISO C++ forbids declaration of `End' with no type
GameEngine.cpp:17: error: syntax error before `}' token
GameEngine.cpp:19: error: syntax error before `::' token
GameEngine.cpp:22: error: `seeder' was not declared in this scope
GameEngine.cpp:22: error: ISO C++ forbids declaration of `srand' with no type
GameEngine.cpp:23: error: `GL_TEXTURE_2D' was not declared in this scope
GameEngine.cpp:23: error: ISO C++ forbids declaration of `glEnable' with no typeGameEngine.cpp:24: error: ISO C++ forbids declaration of `CreateWindow' with no type
GameEngine.cpp:25: error: syntax error before `}' token
GameEngine.cpp:27: error: syntax error before `::' token
GameEngine.cpp:32: error: syntax error before `::' token
GameEngine.cpp:35: error: ISO C++ forbids declaration of `glutInitWindowPosition' with no type
GameEngine.cpp:35: error: initializer list being treated as compound expression
GameEngine.cpp:36: error: `m_iHeight' was not declared in this scope
GameEngine.cpp:36: error: ISO C++ forbids declaration of `glutInitWindowSize' with no type
GameEngine.cpp:36: error: initializer list being treated as compound expression
GameEngine.cpp:37: error: ISO C++ forbids declaration of `glClearColor' with no type
GameEngine.cpp:37: error: initializer list being treated as compound expression
GameEngine.cpp:37: warning: initialization to `int' from `double'
GameEngine.cpp:37: warning: argument to `int' from `double'
GameEngine.cpp:38: error: `GL_PROJECTION' was not declared in this scope
GameEngine.cpp:38: error: ISO C++ forbids declaration of `glMatrixMode' with no type
GameEngine.cpp:39: error: ISO C++ forbids declaration of `glLoadIdentity' with no type
GameEngine.cpp:40: error: ISO C++ forbids declaration of `glOrtho' with no type
GameEngine.cpp:40: error: initializer list being treated as compound expression
GameEngine.cpp:41: error: ISO C++ forbids declaration of `m_window' with no typeGameEngine.cpp:41: error: `glutCreateWindow' was not declared in this scope
GameEngine.cpp:42: error: `Render' was not declared in this scope
GameEngine.cpp:42: error: ISO C++ forbids declaration of `glutDisplayFunc' with no type
GameEngine.cpp:43: error: syntax error before `if'
GameEngine.cpp:47: error: `KeyboardHandling' was not declared in this scope
GameEngine.cpp:47: error: ISO C++ forbids declaration of `glutKeyboardFunc' with no type
GameEngine.cpp:48: error: `SpecialKeyboardHandling' was not declared in this scope
GameEngine.cpp:48: error: ISO C++ forbids declaration of `glutSpecialFunc' with no type
GameEngine.cpp:49: error: `MouseHandling' was not declared in this scope
GameEngine.cpp:49: error: ISO C++ forbids declaration of `glutMouseFunc' with no type
GameEngine.cpp:50: error: `Render' was not declared in this scope
GameEngine.cpp:50: error: ISO C++ forbids declaration of `glutIdleFunc' with no type
GameEngine.cpp:51: error: ISO C++ forbids declaration of `glutMainLoop' with no type
GameEngine.cpp:52: error: syntax error before `}' token
GameEngine.cpp:54: error: syntax error before `::' token
GameEngine.cpp:59: error: syntax error before `::' token
GameEngine.cpp:63: error: `message' was not declared in this scope
GameEngine.cpp:63: error: `strlen' was not declared in this scope
GameEngine.cpp:63: error: syntax error before `;' token
GameEngine.cpp:63: error: syntax error before `++' token
GameEngine.cpp:69: error: syntax error before `::' token
GameEngine.cpp:73: error: ISO C++ forbids declaration of `DrawText' with no typeGameEngine.cpp:73: error: initializer list being treated as compound expression
GameEngine.cpp:73: warning: initialization to `int' from `double'
GameEngine.cpp:73: warning: argument to `int' from `double'
GameEngine.cpp:105: error: syntax error before `if'
And when i add GameEngine.h
i got this:

Quote:

[hylke@DONKER testgameengine]$ g++ -o myprog main.cpp GameEngine.cpp GameEngine.h -L/usr/X11R6/lib -lglut -lGLU -lGL -lXi -lXmu -lX11 -lXext -lm
GameEngine.cpp:1:24: GameEngine.h: No such file or directory
GameEngine.cpp:3: error: syntax error before `::' token
GameEngine.cpp:6: error: ISO C++ forbids declaration of `m_iWidth' with no type
GameEngine.cpp:6: error: `iWidth' was not declared in this scope
GameEngine.cpp:7: error: ISO C++ forbids declaration of `m_iGridX' with no type
GameEngine.cpp:7: error: `GridX' was not declared in this scope
GameEngine.cpp:8: error: ISO C++ forbids declaration of `m_iGridY' with no type
GameEngine.cpp:8: error: `GridY' was not declared in this scope
GameEngine.cpp:9: error: ISO C++ forbids declaration of `m_iGridZ' with no type
GameEngine.cpp:9: error: `GridZ' was not declared in this scope
GameEngine.cpp:10: error: ISO C++ forbids declaration of `bFullscreen' with no type
GameEngine.cpp:10: error: `fullscreen' was not declared in this scope
GameEngine.cpp:11: error: syntax error before `}' token
GameEngine.cpp:13: error: syntax error before `::' token
GameEngine.cpp:16: error: ISO C++ forbids declaration of `End' with no type
GameEngine.cpp:17: error: syntax error before `}' token
GameEngine.cpp:19: error: syntax error before `::' token
GameEngine.cpp:22: error: `seeder' was not declared in this scope
GameEngine.cpp:22: error: ISO C++ forbids declaration of `srand' with no type
GameEngine.cpp:23: error: `GL_TEXTURE_2D' was not declared in this scope
GameEngine.cpp:23: error: ISO C++ forbids declaration of `glEnable' with no typeGameEngine.cpp:24: error: ISO C++ forbids declaration of `CreateWindow' with no type
GameEngine.cpp:25: error: syntax error before `}' token
GameEngine.cpp:27: error: syntax error before `::' token
GameEngine.cpp:32: error: syntax error before `::' token
GameEngine.cpp:35: error: ISO C++ forbids declaration of `glutInitWindowPosition' with no type
GameEngine.cpp:35: error: initializer list being treated as compound expression
GameEngine.cpp:36: error: `m_iHeight' was not declared in this scope
GameEngine.cpp:36: error: ISO C++ forbids declaration of `glutInitWindowSize' with no type
GameEngine.cpp:36: error: initializer list being treated as compound expression
GameEngine.cpp:37: error: ISO C++ forbids declaration of `glClearColor' with no type
GameEngine.cpp:37: error: initializer list being treated as compound expression
GameEngine.cpp:37: warning: initialization to `int' from `double'
GameEngine.cpp:37: warning: argument to `int' from `double'
GameEngine.cpp:38: error: `GL_PROJECTION' was not declared in this scope
GameEngine.cpp:38: error: ISO C++ forbids declaration of `glMatrixMode' with no type
GameEngine.cpp:39: error: ISO C++ forbids declaration of `glLoadIdentity' with no type
GameEngine.cpp:40: error: ISO C++ forbids declaration of `glOrtho' with no type
GameEngine.cpp:40: error: initializer list being treated as compound expression
GameEngine.cpp:41: error: ISO C++ forbids declaration of `m_window' with no typeGameEngine.cpp:41: error: `glutCreateWindow' was not declared in this scope
GameEngine.cpp:42: error: `Render' was not declared in this scope
GameEngine.cpp:42: error: ISO C++ forbids declaration of `glutDisplayFunc' with no type
GameEngine.cpp:43: error: syntax error before `if'
GameEngine.cpp:47: error: `KeyboardHandling' was not declared in this scope
GameEngine.cpp:47: error: ISO C++ forbids declaration of `glutKeyboardFunc' with no type
GameEngine.cpp:48: error: `SpecialKeyboardHandling' was not declared in this scope
GameEngine.cpp:48: error: ISO C++ forbids declaration of `glutSpecialFunc' with no type
GameEngine.cpp:49: error: `MouseHandling' was not declared in this scope
GameEngine.cpp:49: error: ISO C++ forbids declaration of `glutMouseFunc' with no type
GameEngine.cpp:50: error: `Render' was not declared in this scope
GameEngine.cpp:50: error: ISO C++ forbids declaration of `glutIdleFunc' with no type
GameEngine.cpp:51: error: ISO C++ forbids declaration of `glutMainLoop' with no type
GameEngine.cpp:52: error: syntax error before `}' token
GameEngine.cpp:54: error: syntax error before `::' token
GameEngine.cpp:59: error: syntax error before `::' token
GameEngine.cpp:63: error: `message' was not declared in this scope
GameEngine.cpp:63: error: `strlen' was not declared in this scope
GameEngine.cpp:63: error: syntax error before `;' token
GameEngine.cpp:63: error: syntax error before `++' token
GameEngine.cpp:69: error: syntax error before `::' token
GameEngine.cpp:73: error: ISO C++ forbids declaration of `DrawText' with no typeGameEngine.cpp:73: error: initializer list being treated as compound expression
GameEngine.cpp:73: warning: initialization to `int' from `double'
GameEngine.cpp:73: warning: argument to `int' from `double'
GameEngine.cpp:105: error: syntax error before `if'
g++: compilation of header file requested
I gues that's just the same.

aluser 04-15-2004 01:27 PM

GameEngine.h shouldn't go on the command line; it should be #included by whatever file needs it, which it looks like it is. You need to check that GameEngine.h exists and is in the directory with GameEngine.cpp.

hylke 04-15-2004 01:29 PM

it exist and it is in the same directory.

hylke 04-15-2004 01:32 PM

I found this in a file of my directory where i compile the source code using kDevelop.

PHP Code:

####### kdevelop will overwrite this part!!! (begin)##########
bin_PROGRAMS testgameengine

## INCLUDES were found outside kdevelop specific part

testgameengine_SOURCES main.cpp GameEngine.cpp 
testgameengine_LDADD   
= -lglut -lGLU -lGL -lXi -lXmu -lm -lXext -lX11


EXTRA_DIST 
GameEngine.cpp GameEngine.h main.cpp 

####### kdevelop will overwrite this part!!! (end)############
# set the include path found by configure
INCLUDES= $(all_includes)
 
# the library search path.
testgameengine_LDFLAGS = $(all_libraries


aluser 04-15-2004 01:36 PM

looks like kDevelop uses automake. probably it would be a good idea to continue using that.

anyway, are you including GameEngine.h like #include <GameEngine.h> or like #include "GameEngine.h" ? It should be done the second way. I'm not entirely sure if that would cause the problem but it might.

hylke 04-15-2004 01:41 PM

I use #include "GameEngine.h"

aluser 04-15-2004 01:43 PM

I dunno what to tell you except that the compiler doesn't see a GameEngine.h in that directory :(

hylke 04-15-2004 01:57 PM

I wanted to put my GameEngine.h in my GameEngine.cpp and then i saw that i had used <'s instead of "s.
Thank you for your help.
Hylke

EDIT: I have another question:
I want to use texturing but then i need to add the glaux library.But how do i add the glaux library?
thanx again.
Hylke

aluser 04-15-2004 02:09 PM

I'm going to guess that you give -lglaux on the gcc line, and #include some header to use it, perhaps glaux.h. Not having glaux, I can't really know :)


All times are GMT -5. The time now is 03:52 PM.