Date: Wed, 8 May 1996 17:01:55 +0200 (IST) From: Eli Zaretskii To: Martynas Cc: DJGPP mailing list Subject: Re: libraries In-Reply-To: <199605081048.GAA11450@delorie.com> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Wed, 8 May 1996, Martynas wrote: > What is the order ld looks for object files through libraries. I mean, why > does ld take math functions from libm, while they are also found in libc? `ld' searches the files (both objects and libraries) only once, in the order they are listed on the command line. When gcc creates the command line it passes to `ld', it first mentions all the object files and libraries from your original gcc command line (if you mentioned source files, gcc changes their extension to .o, and -l switches are changed to the lib.a names), then appends "libgcc.a libc.a libgcc.a". If your command line includes -lm, `ld' sees libm.a *before* libc.a, so by the time it scans libc.a, the math functions are already resolved. If your command line doesn't include -lm, the math functions will be loaded from libc.a. > I could put object files with empty globbing and env-file functions to some > library and then shorten the executables by linking with it. However, when > I tried that trick some time ago, it didn't work. So what gives? It should have worked. I do this by defining such empty functions on one of the source files I compile, but putting them in a library should work just as well. I suggest you try again and if it doesn't, post the source of these functions and the command line you use to link against that library. You might also find a few `ld' options useful when debugging such problems. The options `-t', `--verbose' and `-y SYMBOL' are the ones you should consider (look them up in the ld Info docs). Gcc lets you pass arbitrary options to the linker by using the `-Wl,option' and `-Xlinker option' switches (described in the gcc Info docs).