PDA

View Full Version : Help I got Serious Problems



xenomorph69
09-06-2002, 02:01 AM
OK Hopefully Someone can help.
I have Tried 3 Compilers, gcc, anjuta, kdevelop, and I get the Same thing. My GL/glut.h and the Libraries will not compile
I am Running Redhat 7.3 and I checked
/usr/include/GL/ and all is fine. Every GL Function is coming up an error.
The error is... Undefined Reference to : "Name of Function in all of My Code. I am still Learning and I am Trying to do the Soloar System Code in OpenGL Programming Third Edition, Any Suggestions? here is My Source Code...

#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>

static int year = 0, day = 0;

void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glPushMatrix();
glutWireSphere(1.0, 20, 16); //Here is the Sun :D
glRotatef((GLfloat) year, 0.0, 1.0, 0.0);
glTranslatef(2.0, 0.0, 0.0);
glRotatef((GLfloat) day, 0.0, 1.0, 0.0);
glutWireSphere(0.2, 10, 8); //This is the Drawing of the Smaller Planet :D
glPopMatrix();
glutSwapBuffers();
}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 'd':
day = (day + 10) % 360;
glutPostRedisplay();
break;
case 'D' :
day = (day - 10) % 360;
glutPostRedisplay();
break;
case 'y':
year = (year + 5) % 360;
glutPostRedisplay();
break;
case 'Y':
year = (year - 5) % 360;
glutPostRedisplay();
break;
default:
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

Any Help would be appreciated
Thanx in advance Guys

satan
09-06-2002, 02:51 AM
I am no C-coder but perhaps it would help to include gl.h, too. And I think you have to tell the linker which libs to link. Something like -lGL -lglut as commandline option for the gcc (and btw you just tried one compiler the gcc - Anjuta and KDevelop are only IDEs and both use the gcc as standard compiler).

hih

OldMan
09-06-2002, 08:19 AM
Firts.. You tried just one compiler... all of them use gcc as compiler.

Did you added the -lGL -lglut in the compile line?

xenomorph69
09-06-2002, 11:48 AM
OK Thank you EveryBody for the Help However Still Pretty New to Linux Development (Came From Windows.
OK I have tried
gcc <sourcename> -|GL
gcc <sourcename> -|glut
gcc -E sourcename
gcc -|GL sourcename


what is the Command Syntax to get it going?
Thanx in advance Guys

xenomorph69
09-06-2002, 11:52 AM
Ok I got it Guys
gcc -lGL -lglut <sourcename>
./a.out

and she runs http://www.opengl.org/discussion_boards/ubb/biggrin.gif

OldMan
09-09-2002, 08:45 AM
the -lLIBNAME is the option to link libraries. You can use -o followed by output name to specify the name of the output program.

DerekKraan
09-29-2002, 08:40 AM
This still doesn't help me. I was getting the same errors, and still can't find a way around them. I'm still learning however, and will probably find a solution before you'll reply. Thanks for the help if you do though. I would really appreciate it.

pkaler
09-29-2002, 03:38 PM
You probably want to use a makefile. Here's the one I use:



EXECUTABLE = demo
CPPFLAGS = -Wall -ggdb3
LIBS = -lGL -lGLU -lglut `sdl-config --cflags --libs`\
-lIL -lILU -lILUT -lopenal
#################################################
CC = gcc
SRCS := $(wildcard *.cpp)
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
DEPS := $(patsubst %.cpp,%.d,$(SRCS))
#################################################
all: $(EXECUTABLE)

$(EXECUTABLE): $(DEPS) $(OBJS)
$(CC) -o $(EXECUTABLE) $(OBJS) $(LIBS)

%.d: %.cpp
$(CC) -M $(CPPFLAGS) $< > $@
$(CC) -M $(CPPFLAGS) $< | sed s/\\.o/.d/ > $@

%.d: %.h
$(CC) -M $(CPPFLAGS) $< > $@
$(CC) -M $(CPPFLAGS) $< | sed s/\\.o/.d/ > $@
clean:
-rm $(OBJS) $(EXECUTABLE) $(DEPS) *~

explain:
@echo "--------Some Info--------"
@echo "Executable name: $(EXECUTABLE)"
@echo "Source files: $(SRCS)"
@echo "Object files: $(OBJS)"
@echo "Dependency files: $(DEPS)"

depends: $(DEPS)
@echo "Dependencies updated"

-include $(DEPS)

tags:
etags *.h *.cpp /usr/include/*.h /usr/include/GL/*.h /usr/include/SDL/*.h

run: all
./$(EXECUTABLE)

debug: all
gdb $(EXECUTABLE)

EXECUTABLE is (surprise) the name of the executable. CPPFLAGS is are the flags that get passed to the compiler.
LIBS is the libraries that are linked to. You probably don't want to change anything else.

You can:
$ make
$ make all
$ make clean
$ make explain
etc.

A little explanation. The makefile runs gcc to figure out all the dependencies for each cpp file. It puts these dependencies in .d files. Then it compiles the files that need to be compiled into .o files. Then links everything together into the executable.

Right now, I'm linking to gl, glu, glut, sdl, DevIL, and openal. You probably don't want to link to all that. And your program will not link correctly if you don't, for example, have the openal libraries on your system. So figure out what libraries you need to link to.

Try
$ man gcc
to figure out what flags that you want to pass to the compiler. -Wall turns all warnings on. -ggdb3 produces debugging symbols for gdb.

pkaler
09-29-2002, 03:40 PM
Btw, check out the pertinent HOWTOs here: http://www.tldp.org/HOWTO/HOWTO-INDEX/programming.html

10-03-2002, 01:08 AM
hi,

i think you got the problem with linux, not with the coding or so.

as all of us face some difficulty, when we change our track to linux from windows.

as i've tried your program, it worked without a single error.

my command line is like the below one, use it, probably it may work for you too

$gcc -o solar solar.c -lglut -lGL -lGLU
$./solar

in the above one, $ is the linux prompt, assumed that your program name is solar.c and will give the executable file name as solar, if you want you can replace them your ones. finally use the second line to run it, if at all compilation is error free.

jmg
10-03-2002, 06:22 PM
Wait a minute...

I always thought that the order you specify the libs matters; gcc wants them in such an order so as to have no unresolved's during linking.

This implies that
-lglut -lglu -lGL would work but, say
-lGL -lglu -lglut or say
-lglu -GL -lglut would fail (because libglut.so and libglu.so have calls in them to functions inside libGL.so).

This doesn't seem to be the case though...(?) Can someone please explain? Has the linker in gcc been "fixed"?

Btw, thanks for the link to the how-to PK.

---j