Problem in compiling with GLUT

i have written a code using glut.h

but when ever i compile it it gives

unknown reference to glutInit
unknown reference to glutDisplayMode

all the glut functions

i don’t know what to do. please help me out

you also need to link to glut. try adding -lglut to the compiler command. if you are using an ide you will need to figure out how to make it do that.

Originally posted by Spiral Man:
you also need to link to glut. try adding -lglut to the compiler command. if you are using an ide you will need to figure out how to make it do that.

What command are you using to compile the code?

OK.

a line as:
gcc blabla.c -c blabla -lglut -lGLU -lGL -lX11 -lXext
can work, but i’m sure that miss some things.

But for the original question: just link it with glut

I have wrote a bash script to increase the development of openGL. The script helps people to compile and link Mesa 3D library.
save the text to a file cc.sh and change it to executable by chmod a+x cc.sh Then type ./cc.sh --help to see how to use it to include OpenGL library properly. It supports OpenGL 3.5, 4.0.
If you are interested in 3D Math visualization , visit my projects : http://sourceforge.net/projects/mathdev/

#!/bin/bash

The shell script was created to compile the c++ source file *.cpp, *.c, *.cxx

, and debug using the GNU debuggin tools such as gdb and gprof

if [ -z “$1” ];
then
echo -e “Missing argument 1
usage: $0 [ filename without .cpp ] [ OPTIONS ]
Type $0 --help for command line options”
exit
fi

The script is :

message of --help

helpMsg="usage: $0 [ filename without .cpp ] [ OPTIONS ]

The bash script accepts the following options :

	-lFilename

			include the library while linking.

			This -l option is different from the -l in gcc compiler.

			It does not search standard system directories but only

			the full filename specified explicitly. For example,

			cc.sh -lmy.o includes my.o while linking. -lmy does not

			search the file libmy.a

	-p

			include the PLIB library,  [http://plib.sourceforge.net/](http://plib.sourceforge.net/

)

	--Mesa4Dir=DIR

			change the default directory of Mesa 3D 4.0 from

			/usr/local/Mesa-4.0 to DIR

	

	-m4

			compile and link using the gcc options for Mesa 3D 4.0

	

	--Mesa35Dir=DIR

			change the default directory of Mesa 3D 3.5 from

			/usr/local/Mesa35 to DIR

	

	-m35

			compile and link using the gcc options for Mesa 3D 3.5

	

	-glui

			include the GLUI library,  [http://www.cs.unc.edu/~rademach/glui/](http://www.cs.unc.edu/~rademach/glui/

)

	-d

			add debugging options for gcc compiler"

compile=

command to compile

cc=“c++”

compile options

cflags=“-W -Wall”
link=

command to link

ccld=“$cc”

libraries to include

libs=

link options

ldflags=“-W -Wall”

start the specific options

debugging options

db=“-a -g -pg”

directories of Mesa 3D library

Mesa4Dir=“/usr/local/Mesa-4.0”
Mesa35Dir=“/usr/local/Mesa35”

loop through all the arguments to determine the directory of Library

for arg in $@ ;
do
case $arg in
# print help message and quit
–help)
echo -e $helpMsg
exit
;;
# find the directory of Mesa 3D 4.0
–Mesa4Dir=)
Mesa4Dir=“echo $arg | sed -e 's/--Mesa4Dir=//'
;;
# find the directory of Mesa 3D 3.5
–Mesa35Dir=
)
Mesa35Dir=“echo $arg | sed -e 's/--Mesa35Dir=//'
;;
esac
done

options for Mesa 3D 4.0

options to compile source code using Mesa 3D 4.0

cflagsM4=“-DHAVE_CONFIG_H -I. -I$Mesa4Dir -I$Mesa4Dir/include -DNDEBUG -g -Wall -fomit-frame-pointer -ffast-math -fstrict-aliasing -malign-loops=2 -malign-jumps=2 -malign-functions=2 -D_REENTRANT -DPTHREADS -c”

options to link Mesa 3D 4.0 library

ldflagsM4=“-g -Wall -fomit-frame-pointer -ffast-math -fstrict-aliasing -malign-loops=2 -malign-jumps=2 -malign-functions=2 -D_REENTRANT -DPTHREADS”

options to include Mesa 3D 4.0 library

libsM4=“$Mesa4Dir/src-glut/libglut.la $Mesa4Dir/si-glu/libGLU.la $Mesa4Dir/src/libGL.la -lm”

command to link Mesa 3D library

ldM=“/bin/sh $Mesa4Dir/libtool --mode=link c++”

options for GLUI

GLuiDir=“/usr/local/Mesa-4.0/src-glui/lib/”

options to include the GLUI library

libsGLUI=“-L$GLuiDir -lglui”

options to include PLIB library

libsPLIB=“-lglut -lGLU -lGL -L/usr/X11/lib -lX11 -lXext -lXmu -lm -lplibssg -lplibsl -lplibpu -lplibfnt -lplibsg -lplibul -lplibnet”

options for Mesa 3D 3.5

options to compile source code using Mesa 3D 3.5

cflagsM35=“-DHAVE_CONFIG_H -I. -I$Mesa35Dir -I$Mesa35Dir/include -DNDEBUG -I$Mesa35Dir/util -I$Mesa35Dir/src/X86 -g -Wall -ffast-math -fexpensive-optimizations -fstrict-aliasing -malign-loops=2 -malign-jumps=2 -malign-functions=2 -D_REENTRANT -DPTHREADS -c”

options to link Mesa 3D 3.5 library

ldflagsM35=“-g -Wall -ffast-math -fstrict-aliasing -malign-loops=2 -malign-jumps=2 -malign-functions=2 -D_REENTRANT -DPTHREADS”
libsM35=“$Mesa35Dir/si-glu/.libs/libGLU.so -L$Mesa35Dir/src $Mesa35Dir/src/.libs/libGL.so -L/usr/X11R6/lib $Mesa35Dir/src-glut/.libs/libglut.so -L$Mesa35Dir/si-glu $Mesa35Dir/src/.libs/libGL.so $Mesa35Dir/src/OSmesa/.libs/libMesaOS.so -lSM -lICE -lXmu -lXext -lXi -lX11 -lpthread -lm -Wl,–rpath -Wl,$Mesa35Dir/si-glu/.libs -Wl,–rpath -Wl,$Mesa35Dir/src/.libs -Wl,–rpath -Wl,$Mesa35Dir/src-glut/.libs -Wl,–rpath -Wl,$Mesa35Dir/src/OSmesa/.libs”

loop through all the arguments

for arg in $@ ;
do
case $arg in
# case of debugging option
-d)
cflags=“$cflags $db”
ldflags=“$ldflags $db”
;;
# case for Mesa 3D 4.0
-m4)
cflags=“$cflags $cflagsM4”
ldflags=“$ldflags $ldflagsM4”
libs=“$libs $libsM4”
ccld=“$ldM”
;;
# case for inclusion of PLIB
-p)
libs=“$libs $libsPLIB”
;;
# case for inclusion of GLUI library
-glui)
libs=“$libs $libsGLUI”
;;
# case for Mesa 3D 3.5
-m35)
cflags=“$cflags $cflagsM35”
ldflags=“$ldflags $ldflagsM35”
libs=“$libs $libsM35”
ccld=“$ldM”
;;
# case for inclusion of addition library files
-l*)
libs=“$libs echo $arg | sed -e 's/-l//'
;;
esac
done

check if the $1.o exists to prevent it from being overwritten

if [ -f $1.o ];
then
echo -e “Attempted to overwrite $1.o
Script exits”
exit
fi

start to compile

compile=“$cc $cflags -c”
link=“$ccld $ldflags $libs”
if [ -f $1.cpp ];
then
$compile $1.cpp

case of the .c file

elif [ -f $1.c ];
then
$compile $1.c

case of the .cxx file

elif [ -f $1.cxx ];
then
$compile $1.cxx
else
echo -e “$1.c, $1.cpp, or $1.cxx file not found”
fi

start to link

if [ -f $1.o ];
then
$link -o $1 $1.o
# move or remove the object file after linking
if [ -d ./.libs ]
then
mv --force $1.o ./.libs/
else
rm --force $1.o
fi
fi

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.