automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting 'undefined reference' errors during linking but I think I in


From: cs
Subject: Re: Getting 'undefined reference' errors during linking but I think I included all libraries?!?
Date: Fri, 2 May 2003 08:55:33 -0700 (MST)

Thanks.  I'm /very/ happy this got cleared up.

Chris

 -------- Original Message --------
   Subject: Re: Getting 'undefined reference' errors during linking but I
think I included all libraries?!?
   From: "Rusty Ballinger" <address@hidden>
   Date: Fri, May 2, 2003 1:08 am
   To: address@hidden

   > Did you know that when you link all the stuff to make
   > the executable that the *order matters*?!?!?

   (A more serious & deep-seated problem, I think, is that order matters
   when running individual commands.  For years I have been waiting for
   this sort of thing to get fixed:

     $ rm -f foo
     #  wait, I need that stuff!  better make a backup.
     $ cp foo foo.bak
     cp: cannot stat `foo': No such file or directory

   "You bastards!")

   > gcc -o myprogram myprogram.o func1.o func2.o
   >       -L $(srcdir)/libs -lsomearchive -lm -lX11
   >        -lpthread -L somepath ...etc.
   >
   > The -L guys *must* be *after* the object files!!!!
   > The whole reason for my problem was that I put the
   > -L stuff in my name_LDFLAGS line instead of
   > name_LDADD!!!

   I don't think that's true:

     $ g++ -o foo foo.o -lsomeLib
     /tmp/cc2eBnZJ.o: In function `main':
     /tmp/cc2eBnZJ.o(.text+0x1e): undefined reference to [...]
     collect2: ld returned 1 exit status

     $ g++ -L/usr/tmp/somelibdir -o foo foo.o -lsomeLib
     $

   That's with gcc 3.2, but I think any compiler will be the same.  I
   think all that matters is that the -L precedes the -l.

   > Not only that but if some libraries depend on other ones
   > then you must be careful of the /order/ you specify all the -l guys
   > in!!!

   Yes, "but", your compiler's man page or other documentation will tell
   you that.  (& although I think putting all your -L's in LDFLAGS is
   probably fine, you can get finer control, if you need it, by putting
   "-L/path/to/foolib -lfoo -L/path/to/barlib -lbar" etc. in LDADD.
   Also, automake's info page does say it's OK to put -L's in LDADD.)

   > I kept modifying the gcc link line and finally got one
   > that WORKED!!! The trick now is getting Makefile.am to reflect
   > that.

   You "should" be able to just put your -l's in the right order in LDADD
   or foo_LDADD; isn't automake leaving them alone?

   (also, in case it's not clear, although -L's and -l's can be
   intermixed, the -L which says where to find a library needs to precede
   the -l which gives the name of that library.)

   --Rusty







reply via email to

[Prev in Thread] Current Thread [Next in Thread]