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 status
I 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>
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.
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?
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.
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 , Great idea!
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 ] && source /etc/profile.d/bash-completion
source /etc/profile
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.