PDA

View Full Version : Compilation issue - Probably very simple :)



Infamy
01-19-2005, 06:44 AM
Hello everyone,

I am attempting to compile my first OpenGL program, but I run into the following errors:


$ gcc hellok.c
hellok.c:49:2: warning: no newline at end of file
/tmp/ccQrLcMW.o(.text+0xe): In function `display':
: undefined reference to `glClear'
/tmp/ccQrLcMW.o(.text+0x2d): In function `display':
: undefined reference to `glColor3f'
/tmp/ccQrLcMW.o(.text+0x39): In function `display':
: undefined reference to `glBegin'
/tmp/ccQrLcMW.o(.text+0x58): In function `display':
: undefined reference to `glVertex3f'
/tmp/ccQrLcMW.o(.text+0x77): In function `display':
: undefined reference to `glVertex3f'
/tmp/ccQrLcMW.o(.text+0x96): In function `display':
: undefined reference to `glVertex3f'
/tmp/ccQrLcMW.o(.text+0xb5): In function `display':
: undefined reference to `glVertex3f'
/tmp/ccQrLcMW.o(.text+0xba): In function `display':
: undefined reference to `glEND'
/tmp/ccQrLcMW.o(.text+0xbf): In function `display':
: undefined reference to `glFlush'
/tmp/ccQrLcMW.o(.text+0xef): In function `init':
: undefined reference to `glClearColor'
/tmp/ccQrLcMW.o(.text+0xfb): In function `init':
: undefined reference to `glMatrixMode'
/tmp/ccQrLcMW.o(.text+0x100): In function `init':
: undefined reference to `glLoadIdentity'
/tmp/ccQrLcMW.o(.text+0x12c): In function `init':
: undefined reference to `glOrtho'
/tmp/ccQrLcMW.o(.text+0x150): In function `main':
: undefined reference to `glutInit'
/tmp/ccQrLcMW.o(.text+0x15c): In function `main':
: undefined reference to `glutInitDisplayMode'
/tmp/ccQrLcMW.o(.text+0x170): In function `main':
: undefined reference to `glutInitWindowSize'
/tmp/ccQrLcMW.o(.text+0x184): In function `main':
: undefined reference to `glutInitWindowPosition'
/tmp/ccQrLcMW.o(.text+0x190): In function `main':
: undefined reference to `glutCreateWindow'
/tmp/ccQrLcMW.o(.text+0x1a1): In function `main':
: undefined reference to `glutDisplayFunc'
/tmp/ccQrLcMW.o(.text+0x1a6): In function `main':
: undefined reference to `glutMainLoop'
collect2: ld returned 1 exit statusI get the impression that I have not included certain libraries, but I am not sure really what I am missing. Here is what I have included:


#include <GL/glut.h> // Header File For The GLUT Library
#include </usr/lib/opengl/ati/include/gl.h> // Header File For The OpenGL32 Library
#include <GL/glu.h> // Header File For The GLu32 Library
#include </usr/lib/opengl/ati/include/glx.h>

#include<stdio.h>
#include<math.h>
#include<stdlib.h>Thanks a lot for the help,

Infamy

jide
01-19-2005, 08:48 AM
You should not only include the library headers, but also link with them. The compiler simply cannot know which libraries you are using but the libc, stdlib and as for C++ ones.

Just add -lGL -lGLU to your command line.

Do the same for all the other libraries you need.

Infamy
01-19-2005, 09:48 AM
Ok, Sorry about the hand holding here...

# gcc -lGL -lGLU -lglut hellok.c allowed me to compile fine.

In the future, How would I include that into the actual program? It seems to not have worked the way I did it above.

Also, is there something similiar to microsoft visual studio for linux? I am looking for a debugger and such..

Thanks a ton,

Infamy

jide
01-19-2005, 01:18 PM
Originally posted by Infamy:

In the future, How would I include that into the actual program? It seems to not have worked the way I did it above.
What do you mean here ? I don't understand.


Originally posted by Infamy:

Also, is there something similiar to microsoft visual studio for linux? I am looking for a debugger and such..
There are several IDE like Kdevelop.


Originally posted by Infamy:

Thanks a ton,

InfamyThanks suffices.

Infamy
01-19-2005, 04:41 PM
What do you mean here ? I don't understand. I mean that I do not wish to type in 'gcc -lGL -lGLU -lglut' everytime I want to compile a program, I would rather just 'gcc hellok.c'. Is there a way to either adjust gcc or my program so that those extra flags become unnecessary?

Thanks,

Infamy

jide
01-20-2005, 12:39 AM
no.

ZbuffeR
01-20-2005, 12:49 AM
Simply put the command on a simple shell script, or use a Makefile (or other compilation management system).

RigidBody
01-21-2005, 12:24 AM
or just put

alias gcc 'gcc -lGL -lGLU -lglut'

in your $HOME/.cshrc (or $HOME/.bashrc, depending on your shell)

jide
01-21-2005, 02:01 AM
Originally posted by GreetingsFromMunich:
or just put

alias gcc 'gcc -lGL -lGLU -lglut'

in your $HOME/.cshrc (or $HOME/.bashrc, depending on your shell):D :D :D :D

Volker
01-21-2005, 03:11 AM
Originally posted by Infamy:
Also, is there something similiar to microsoft visual studio for linux? I am looking for a debugger and such..As a debugger, you can use ddd, which is a graphical frontend to gdb.
I've tried several IDE's (eventually sticking to vim :) , Anjuta seems to have some potential if you are used to Visual Studio, and of course KDevelop, though I never really used it. Some devs I know of also use Eclipse. It's really up to you, just try them all and pick the one you like.

Cheers
Volker

Infamy
01-21-2005, 05:49 AM
Ok, I have started to use kdevelop and it is going well. I would like to add those options to the makefile for the program. At what point in the makefile would I add them? I have browsed through and nothing looks like something I would want to touch...

I am assuming that most makefiles are similiar, so does anyone know what section of the makefile I would edit to add the -lGL -lGLU -lglut options?

**UPDATE** Thanks, my browser did not update properly, Thanks for the alias suggestion :p , Great idea!

Thanks,

Infamy

Infamy
01-21-2005, 07:26 AM
Hmm, I put that alias in and I still have the issues I was having before when it could not find the libraries. The is my .bashrc:


# colors for ls, etc.
eval `dircolors -b /etc/DIR_COLORS`
alias d="ls --color"
alias ls="ls --color=auto"
alias ll="ls --color -l"
alias gcc 'gcc -lGL -lGLU -lglut'
# Change the window title of X terminals
case $TERM in
xterm*|rxvt|Eterm|eterm)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
;;
screen)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
;;
esac

##uncomment the following to activate bash-completion:
#[ -f /etc/profile.d/bash-completion ] &amp;&amp; source /etc/profile.d/bash-completion
source /etc/profileThanks,

Infamy

jide
01-21-2005, 11:52 AM
Don't do that. It will simply provoke all your compilations using gcc to link with those libraries...

Well, simply append at your gcc command -lGL -lGLU -lglut.

Is that so much a hard over-work ?

Otherwise, you'll need to learn how to make Makefiles. Internet is a good place for that.

Infamy
01-21-2005, 12:29 PM
It isn't hard work, but in my instance, where I am using kdevelop, I need gcc to know what libs to use so that when I tell it to build, it can build it without errors. It is certainly no problem if I were to just build the source by hand.

Infamy
01-21-2005, 03:04 PM
Got it, I was able to add the compiler options within kdevelop itself, and everything works nicely.

Thanks everyone for your suggestions,

Infamy