Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Question on header files and their use.

Reply
Thread Tools

Question on header files and their use.

 
 
Ben Bacarisse
Guest
Posts: n/a
 
      03-30-2011
BruceS <> 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 an IDE
(particularly for non-standard headers).

> Are you talking about some name-replacement macro making what looks
> like a call to foo() actually a call to bar(), or something else
> entirely? Maybe it's just too early in the morning, but this sounds
> like something I'm not aware of, and I always appreciate learning new
> things about C.


I doubt it happens. The point I was making was that without any
information from the OP, we are left to speculate about what might be
going on including things that I can only image in hypothetical
environments.

--
Ben.
 
Reply With Quote
 
 
 
 
robertwessel2@yahoo.com
Guest
Posts: n/a
 
      03-30-2011
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 an IDE
> (particularly for non-standard headers).



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.
 
Reply With Quote
 
 
 
 
BruceS
Guest
Posts: n/a
 
      03-31-2011
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 an IDE
> > (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. Thanks Robert.
 
Reply With Quote
 
robertwessel2@yahoo.com
Guest
Posts: n/a
 
      03-31-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
UNIX header files to Windows header files anand.ba@gmail.com C Programming 3 05-01-2006 03:57 PM
Header files included in header files John Smith C Programming 18 07-24-2004 04:55 AM
What the pros use to power their flashes... and their digital cameras. Dan Sullivan Digital Photography 21 01-04-2004 04:40 PM
Seperate compilation (header files n' their implementations) Chris Mantoulidis C++ 3 12-20-2003 04:25 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57