This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: makefile


>-----Original Message-----
>From: Lars Kristiansson [mailto:md8lars@mdstud.chalmers.se]
>Sent: 26 February 2001 07:40

>fraggel39> make uppg41
>gcc -I/users/mdstud/graf/old1999/OPENGL99 -I/usr/X11/include -pipe
>-fpic -O3 -DSHM -c  -c  uppg4.c
>gcc -O3 -c myrnd.c
>gcc -L/usr/openwin/lib -L/opt/SUNWmotif/lib
>-L/usr/src/md/pd/X11/libs/glut-3.7/lib/glut
>-L/usr/src/md/pd/X11/libs/glut-3.7/lib/mui -R/usr/openwin/lib
>-R/usr/local/lib -R/usr/X11/lib -R/opt/SUNWmotif/lib -lmui -lglut -lGLU
>-lGL -lm -L/usr/ucblib -R/usr/ucblib -lX11 -lXm -lXmu -lXext -lnsl
>-lsocket -lucb -lgen -o uppg4 uppg4.o myrnd.o
>Undefined                       first referenced
> symbol                             in file
>glutCreateWindow                    uppg4.o
>glutMainLoop                        uppg4.o
>glutDisplayFunc                     uppg4.o
>glutReshapeFunc                     uppg4.o
>glutMouseFunc                       uppg4.o
>glutInitDisplayMode                 uppg4.o
>glutMotionFunc                      uppg4.o
>glutPostRedisplay                   uppg4.o
>glutInitWindowSize                  uppg4.o
>ld: fatal: Symbol referencing errors. No output written to uppg4
>*** Error code 1
>make: Fatal error: Command failed for target `uppg41'
>--------------------------------------------------------------------
>
>and I don't know what's wrong? Everything is included and linked just as
>it should be supposed to, but the libraryfunctions in glut doesn't seem to
>be found at all!

  This is the problem:

>gcc -L/usr/openwin/lib -L/opt/SUNWmotif/lib
>-L/usr/src/md/pd/X11/libs/glut-3.7/lib/glut
>-L/usr/src/md/pd/X11/libs/glut-3.7/lib/mui -R/usr/openwin/lib
>-R/usr/local/lib -R/usr/X11/lib -R/opt/SUNWmotif/lib -lmui -lglut -lGLU
>-lGL -lm -L/usr/ucblib -R/usr/ucblib -lX11 -lXm -lXmu -lXext -lnsl
>-lsocket -lucb -lgen -o uppg4 uppg4.o myrnd.o

  You need to specify all of your application's .o files *first* on the 
linker command line, and all the libraries *last*.  This is because the
linker works by remembering what undefined symbols it comes across as it
goes along, and extracting the required modules from the library archives
and linking them to your application.

  If you put the libs on the command line first, it processes them all
before
it knows any of the undefined symbols that your program wants, and so
doesn't
extract anything from the libs.  Then it processes your applications, finds
all the undefined symbols, and remembers them.  Then it's run out of files
to
process and it hasn't resolved your symbols, so it gets an error.

  If you put your app files first, it processes them and remembers all the
undefined symbols, then as it runs through the libs it finds the functions
they reference and links them into the final exe.

  Yes, the linker could and should be a bit cleverer about this.  But until
it is, the fix is to put your .o files first.

        DaveK
-- 
"Never give succor to the mentally ill; it is a bottomless pit."  
  -- William S. Burroughs


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]