Compilation of OpenGL Redbook sample code

 

 

http://download.csdn.net/detail/gflytu/4110817#comment

 

kgui@linuxamd:~/Downloads/redbook$ gcc -lglut -lGL -lGLU aaindex.c

aaindex.c:(.text+0x2f7): undefined reference to `glutInit'
aaindex.c:(.text+0x303): undefined reference to `glutInitDisplayMode'
aaindex.c:(.text+0x317): undefined reference to `glutInitWindowSize'
aaindex.c:(.text+0x324): undefined reference to `glutCreateWindow'
aaindex.c:(.text+0x335): undefined reference to `glutReshapeFunc'
aaindex.c:(.text+0x341): undefined reference to `glutKeyboardFunc'
aaindex.c:(.text+0x34d): undefined reference to `glutDisplayFunc'
aaindex.c:(.text+0x352): undefined reference to `glutMainLoop'
collect2: error: ld returned 1 exit status


Then, re-install

sudo apt-get install freeglut3-dev 

Reading package lists... Done
Building dependency tree       
Reading state information... Done
freeglut3-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 158 not upgraded.

Then, use cmd below and it pass compilation

gcc teapot.c -c -lGL -lGLU -lglut

gcc aaindex.c -c -lGL -lGLU -lglut

 

Then, How to modify Makefile?

 

#
# Copyright (c) 1993-1997, Silicon Graphics, Inc.
# ALL RIGHTS RESERVED
# Permission to use, copy, modify, and distribute this software for
# any purpose and without fee is hereby granted, provided that the above
# copyright notice appear in all copies and that both the copyright notice
# and this permission notice appear in supporting documentation, and that
# the name of Silicon Graphics, Inc. not be used in advertising
# or publicity pertaining to distribution of the software without specific,
# written prior permission.
#


TARGETS = aaindex aapoly aargb accanti accpersp \
        alpha alpha3D bezcurve bezmesh bezsurf \
        clip colormat cube dof double \
        drawf feedback fog fogindex font hello \
        image light lines list material \
        model movelight pickdepth picksquare planet \
        polys quadric robot scene select \
        smooth stencil stroke surface teapots tess \
        tesswind checker mipmap \
    polyoff texbind texgen texprox texsub varray wrap \
        texturesurf torus trim unproject

LLDLIBS = -lglut -lGLU -lGL

default: $(TARGETS)

all: default

.c.o:
    cc -c -I/usr/include -I$(TOP) $<

$(TARGETS): $$@.o
    cc $@.o $(LLDLIBS) -o $@

clean:  
    -rm -f *.o $(TARGETS)

 

Modified to makefile as below

 

TARGETS = aaindex aapoly aargb accanti accpersp \
        alpha alpha3D bezcurve bezmesh bezsurf \
        clip colormat cube dof double \
        drawf feedback fog fogindex font hello \
        image light lines list material \
        model movelight pickdepth picksquare planet \
        polys quadric robot scene select \
        smooth stencil stroke surface teapots tess \
        tesswind checker mipmap \
    polyoff texbind texgen texprox texsub varray wrap \
        texturesurf torus trim unproject

OBJS=$(patsubst %.c,%.o,$(SRCS))

LLDLIBS = -lglut -lGLU -lGL -lm
default: $(TARGETS)

all:default

$(TARGETS):$(OBJS)
    gcc $@.c $(LLDLIBS) -o $@

clean:  
    rm -f *.o $(TARGETS)

 

 make -f Makefile.ubuntu

gcc texbind.c -lglut -lGLU -lGL -lm  -o texbind
gcc texgen.c -lglut -lGLU -lGL -lm  -o texgen
gcc texprox.c -lglut -lGLU -lGL -lm  -o texprox
gcc texsub.c -lglut -lGLU -lGL -lm  -o texsub
gcc varray.c -lglut -lGLU -lGL -lm  -o varray
gcc wrap.c -lglut -lGLU -lGL -lm  -o wrap
gcc texturesurf.c -lglut -lGLU -lGL -lm  -o texturesurf
gcc torus.c -lglut -lGLU -lGL -lm  -o torus
gcc trim.c -lglut -lGLU -lGL -lm  -o trim
trim.c: In function ‘init’:
trim.c:110:21: warning: passing argument 3 of ‘gluNurbsCallback’ from incompatible pointer type [enabled by default]
                     nurbsError);
                     ^
In file included from /usr/include/GL/freeglut_std.h:129:0,
                 from /usr/include/GL/glut.h:17,
                 from trim.c:45:
/usr/include/GL/glu.h:319:23: note: expected ‘_GLUfuncptr’ but argument is of type ‘void (*)(GLenum)’
 GLAPI void GLAPIENTRY gluNurbsCallback (GLUnurbs* nurb, GLenum which, _GLUfuncptr CallBackFunc);
                       ^
gcc unproject.c -lglut -lGLU -lGL -lm  -o unproject

 

 

posted @ 2014-06-30 20:28  Gui Kai  阅读(395)  评论(0编辑  收藏  举报