On Mar 30, 9:02*pm, BruceS <bruce...@hotmail.com> wrote:
> On Mar 30, 11:51*am, "robertwess...@yahoo.com"
>
>
>
>
>
> <robertwess...@yahoo.com> wrote:
> > On Mar 30, 11:26*am, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
>
> > > BruceS <bruce...@hotmail.com> writes:
> > > > On Mar 29, 7:06*am, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> > > > <snip>
> > > >> <string.h> need not be a file and "including" it can have all sorts of
> > > >> effects other than just declaring things. *It might, for example,
> > > >> trigger linking against the right library.
> > > > <snip>
>
> > > > How does including a header trigger linking to a specific library?
>
> > > Why could it not? *I'm not talking about something that does happen,
> > > just something that might. *It would be very useful behaviour in anIDE
> > > (particularly for non-standard headers).
>
> OK. *Thanks, Ben. *I thought you had something specific in mind, and
> was looking forward to learning a new wrinkle.
>
> > For at least one example where you can do just that, MS VC allows you
> > to specify:
>
> > * *#pragma comment(lib, "libraryname")
>
> > Which adds libraryname.lib to the list of libraries to be searched by
> > the linker.
>
> > I don't think GCC has an equivalent.
>
> This is more what I was wondering about. *So if you just compile, the
> pragma has done something with the .o that leads the linker to later
> include libraryname in the list? *That's actually pretty cool. *I
> generally use VC just for C# and C++, not C. *I'll have to try that
> out, if I can think of a situation where I'd want to specify a library
> in source.
In MS's case, this used to be done with a COMENT record in the OMF*
file, with a particular subtype (0x9f**, if anyone cares) specifying
that the string contains a library name. This is where the #pragma
got its name.
These days, MSVC writes a .drectve section into the PE/COFF object
file, which contains a linker command line parameter string (which the
linker parses along with the "real" command line. So if you'd put the
above #pragma in some code, you'd find '/DEFAULTLIB:"libraryname" '
in a string referenced from the .drectve section.
This works in (unmanaged) C++, too, of course, and there are
provisions for the same sort of data in a .NET assembly, but I've
never cared about the internals of MSIL object files enough to figure
out the details.
*The old, Intel defined, object module format that MS used before
switching to PE/COFF for Win32
**I’m not sure if that’s an Intel defined subtype, or an MS extension
|