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
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
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 :
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=
cc=“c++”
cflags=“-W -Wall”
link=
ccld=“$cc”
libs=
ldflags=“-W -Wall”
db=“-a -g -pg”
Mesa4Dir=“/usr/local/Mesa-4.0”
Mesa35Dir=“/usr/local/Mesa35”
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
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”
ldflagsM4=“-g -Wall -fomit-frame-pointer -ffast-math -fstrict-aliasing -malign-loops=2 -malign-jumps=2 -malign-functions=2 -D_REENTRANT -DPTHREADS”
libsM4=“$Mesa4Dir/src-glut/libglut.la $Mesa4Dir/si-glu/libGLU.la $Mesa4Dir/src/libGL.la -lm”
ldM=“/bin/sh $Mesa4Dir/libtool --mode=link c++”
GLuiDir=“/usr/local/Mesa-4.0/src-glui/lib/”
libsGLUI=“-L$GLuiDir -lglui”
libsPLIB=“-lglut -lGLU -lGL -L/usr/X11/lib -lX11 -lXext -lXmu -lm -lplibssg -lplibsl -lplibpu -lplibfnt -lplibsg -lplibul -lplibnet”
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”
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”
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
if [ -f $1.o ];
then
echo -e “Attempted to overwrite $1.o
Script exits”
exit
fi
compile=“$cc $cflags -c”
link=“$ccld $ldflags $libs”
if [ -f $1.cpp ];
then
$compile $1.cpp
elif [ -f $1.c ];
then
$compile $1.c
elif [ -f $1.cxx ];
then
$compile $1.cxx
else
echo -e “$1.c, $1.cpp, or $1.cxx file not found”
fi
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.