From: colin AT fu DOT is DOT saga-u DOT ac DOT jp (Colin Peters) Subject: RE: B19: Link error between libs linked with -l 29 Sep 1998 15:36:33 -0700 Message-ID: <001b01bdeb50$f7d53ca0$fa173185.cygnus.gnu-win32@gbird0.fu.is.saga-u.ac.jp> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit To: "GNU-win32" Cc: "Adam Chlipala" , "Mumit Khan" Mumit Khan wrote: >On Sun, 27 Sep 1998, Adam Chlipala wrote: > >> When I do something like the following: >> gcc file.c -l1 -l2 >> I get linker errors involving functions found in 1 and used in 2. When >> I move a lib to the cwd and do: >> gcc file.c lib1.a -l2 >> all is well. Am I doing something incorrectly here or is this a bug? > >When you use -l, you must also supply a -L to tell >the linker where to find it (unless it's in one of the standard or >default directories). [snip] Actually this looks like a simple link order error to me. If I'm not mistaken, in gcc if an object uses a symbol in a library that library must appear *after* the object that requires it on the command line. The exception to this rule is if the object in the library that contains the required symbol has already been linked in, either by another reference in earlier code or, as happens in the second case above, all the objects in the library are linked in explicitly (when you include a library on the command line directly instead of using -l then all the objects in the library are linked in, whether your code references them or not). The solution, if I'm correct, is: gcc file.c -l2 -l1 If the two librarys are interdependent then you may have to list them twice (or more times!): gcc file.c -l2 -l1 -l2 which is just one fine argument for getting rid of cycles in your dependency graphs. Hope I'm right :) Colin. PS. For even more fun, if you have a symbol defined in two libraries the one in the first library on the command line (after the referencing object) will be used and there will be no error. You get errors when two objects are forced to be linked in with duplicate symbols. It's wonderfully complicated. - Colin Peters - colin at fu.is.saga-u.ac.jp - http://www.geocities.com/Tokyo/Towers/6162/index.html - Go not to usenet for counsel, for it will say both - 'yes' and 'no' and 'try another newsgroup'. - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".