From: Keith M. <kei...@us...> - 2007-11-05 20:27:46
|
On Mon, 2007-11-05 at 18:03 +0100, Ralf Wildenhues wrote: > * Brian Dessent wrote on Mon, Nov 05, 2007 at 05:11:21PM CET: > > Pau Garcia i Quiles wrote: > > > > > Thank you. I wonder why the same code, with the same Makefiles, builds > > > fine on Linux, no need to change the order of the -l parameters to the > > > linker :-? > > > > Because ELF and PE work differently. > > > > BTW you see the same behavior on ELF if you are doing static linking; it > > is only in the shared case that order does not matter. > > It matters even in the shared case for ELF. The consequences just > happen to be visible less frequently, and the issue is off topic here. The bottom line is that the OP's usage case:-- On Mon, 2007-11-05 at 15:36 +0100, Pau Garcia i Quiles wrote: > Apparently everything works fine, except for the fact that linkage > only works if specified after the source files. I. e. this does not > work: > g++ -shared-libgcc -lstdc++_s -o test test.cpp is technically incorrect, on all platforms. That you may get away with it, in certain circumstances as an accidental side effect of how shared object libraries may be processed on ELF platforms, does not legitimise it; in these circumstances it is simply an "error not caught". `-l<libname>' arguments to gcc, or to ld, are not arbitrary options which may be collected at the start of the command line; they are positionally significant, in relation to the object file names which require them. > but this works: > g++ -o test test.cpp -shared-libgcc -lstdc++_s This is documented correct syntax, so... > Is that behavior intented? ...yes. > (I'd say no) If you say so, then perhaps you should spend some more time acquainting yourself with `info gcc' and `info ld'. Regards, Keith. |