NO

Author Topic: Library to header correlation...  (Read 9127 times)

Anonymous

  • Guest
Library to header correlation...
« on: January 25, 2005, 03:13:28 am »
Ok, I'm just thinking out loud here, but...

Since there is an obvious correlation between headers and libraries in your C distribution, wouldn't it make sense to put #pragma lib "..." lines in each of your headers?

eg.  in the shellapi.h header add #pragma lib "shell32.lib" so that the correct library is automatically added to the linker's list whenever we include a header.  It would completely eliminate the linker errors related to us forgetting to manually add the libraries (or not being sure which libraries to add) to the linker settings...

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 1974
    • http://www.smorgasbordet.com
Library to header correlation...
« Reply #1 on: January 25, 2005, 03:00:59 pm »
I don't have the entire Windows #include file tree at the top of my head, but it can't be an exact 1:1 mapping between include files and libraries (100+ libraries and 300+ include files). Part of the process of producing import libraries (*.lib) is automated, so maybe I can do something in that area... I will look at it.

Not sure how useful it is, but the linker will accept a *.lib file specification (using wildcards) - maybe this feature can be used? I havn't actually tried it (from a project file)...

Pelle
/Pelle

Anonymous

  • Guest
Library to header correlation...
« Reply #2 on: January 25, 2005, 09:44:53 pm »
Quote from: "Pelle"
I don't have the entire Windows #include file tree at the top of my head, but it can't be an exact 1:1 mapping between include files and libraries (100+ libraries and 300+ include files). Part of the process of producing import libraries (*.lib) is automated, so maybe I can do something in that area... I will look at it.


As I said I was just thinking out loud... almost wishing.

It sounds like I might be setting you a massive task, and I rather suspect you have a full day already.  

Tell you what... don't do anything on it for a few days... let me look at a couple of ideas and see if I can't solve this one for you, without massive changes to your headers or code.

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 1974
    • http://www.smorgasbordet.com
Library to header correlation...
« Reply #3 on: January 25, 2005, 10:20:39 pm »
Quote from: "ldblake"
It sounds like I might be setting you a massive task, and I rather suspect you have a full day already.

For the moment, yes. But it's a good idea - it would simplify things.

Quote from: "ldblake"

Tell you what... don't do anything on it for a few days... let me look at a couple of ideas and see if I can't solve this one for you, without massive changes to your headers or code.

OK - thanks.

Pelle
/Pelle

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1828
Libs
« Reply #4 on: January 26, 2005, 06:36:19 am »
First Aid:

You could make include file for example libs.h
and insert known libs to there.

// libs.h
#ifdef _SHELLAPI_H
#pragma lib "shell32.lib"
#endif
May the source be with you

Anonymous

  • Guest
Re: Libs
« Reply #5 on: January 26, 2005, 08:18:23 am »
Quote from: "timovjl"
First Aid:

You could make include file for example libs.h
and insert known libs to there.

// libs.h
#ifdef _SHELLAPI_H
#pragma lib "shell32.lib"
#endif


Yep.  I was, in fact, just thinking about that.  It needs to be a little more complex than the example and it would have to be the last on the list but it would work.  

Something like...
Code: [Select]

#ifdef _SHELLAPI_H_

#ifndef SHELl32_LIB
#define SHELL32_LIB
#pragma lib "shell32.lib"
#end if

#end if

... repeated for each header.  The extra would be necessary to prevent duplicating the pragmas since there is often more than one header for each library and sometimes more than one library for a header.

The ideal would be to include the middle part (between the blank lines above)  into the actual headers themselves...  I'd be happy to do the work and contribute it to the project... From there, Pelle would just have to keep it up to date.  What I need, though, is some kind of crossreference to work from...  What goes with what?

I wonder if there's a list someplace???

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 1974
    • http://www.smorgasbordet.com
Re: Libs
« Reply #6 on: January 26, 2005, 12:18:23 pm »
Quote from: "ldblake"
The ideal would be to include the middle part (between the blank lines above)  into the actual headers themselves...  I'd be happy to do the work and contribute it to the project... From there, Pelle would just have to keep it up to date.  What I need, though, is some kind of crossreference to work from...  What goes with what?

I wonder if there's a list someplace???

This is the big question. I'm not aware of any such list, but maybe there is one. With this info, I can easily write a small script to insert the necessary lines into the #include files.

Pelle
/Pelle

Anonymous

  • Guest
Re: Libs
« Reply #7 on: January 26, 2005, 04:36:57 pm »
Quote from: "Pelle"
Quote from: "ldblake"
I wonder if there's a list someplace???

This is the big question. I'm not aware of any such list, but maybe there is one. With this info, I can easily write a small script to insert the necessary lines into the #include files.
Pelle


Fear Not!  :)   I'm half way there!

1) I took your sysdefs.tag file and parsed it down to a csv list of functions in each header.  As :  <function>,<header>

2) I used polib to list all the stuff in the libraries, giving me a list of functions in each library.   (300 + files worth... Thank goodness for batch files!)

3) Next I just have to tap up a little code to transform the library list files into a csv list of functions by library.  As :  <function>,<library>

4) Then all I have to do is tap up one last bit of code to sort and correlate the function names producing a list of  libraries by header.  Take out the duplicate lines and the final output would be a text file consiting of:

<header name>,<library name>
<header name>,<library name>
<header name>,<library name>

It shouldn't take long...  From there it would be a matter of sequentially opening each header, locating the header's #define _HEADER_H line and tucking in the required number of #pragma blocks, as in my earlier message.  

(There will be multiple lines for some headers, if they call in more than one library, so your script will have to account for that.  It's also possible some headers won't be referenced at all, if they don't match up to a library.)


Will this do as a source list for your script?

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 1974
    • http://www.smorgasbordet.com
Re: Libs
« Reply #8 on: January 26, 2005, 05:21:05 pm »
Quote from: "ldblake"
Will this do as a source list for your script?

Sure - this list (in pretty much any format) is exactly what I need!

Pelle
/Pelle

Anonymous

  • Guest
Re: Libs
« Reply #9 on: January 26, 2005, 06:24:39 pm »
Quote from: "Pelle"
Quote from: "ldblake"
Will this do as a source list for your script?

Sure - this list (in pretty much any format) is exactly what I need!

Pelle


Excellent...

I just finished transforming all the library listings...

One more editor nacro to correlate names and we're home free!

You should have it sometime later today...

Anonymous

  • Guest
Re: Libs
« Reply #10 on: January 27, 2005, 12:50:15 am »
Quote from: "Pelle"
Quote from: "ldblake"
Will this do as a source list for your script?

Sure - this list (in pretty much any format) is exactly what I need!
Pelle


 :) Here ya go!

I think I should say how I built this list...

As I explained before I used polib to give me a list of all the function calls in the libraries.  I then took your sysdef.tg file apart to get a list of stuff in the headers.

This means 2 things... first, the list is only as complete as the matchup beteen your data base names and the library names.  This might be further degraded if I didn't "undecorate" some of the OBJ libs correctly.  I'm pretty sure I got the DDL imports right, though...

I had my little quicky code include a match in the list if:
A) the library and header names were the same
B) a function name was listed in both places.

To play it safe I had my code output a list of library functions that didn't get crossreferenced.  (H2LRept.txt) I'm sure a lot of them are deliberate, avoiding conflicts, internal functions and such.  But it struck me that maybe some of them weren't so I thought I'd give you the information and let you decide what to do with it.

The main crossreference is in HDR2LIB.CSV which has 241 matchups.  Given that not all headers reference libraries and a lot of the headers are simply included in other headers I'd say I got a good 90% of them for you.

Let me know how it goes!

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 1974
    • http://www.smorgasbordet.com
Library to header correlation...
« Reply #11 on: January 27, 2005, 12:09:52 pm »
Thank you for the files! I will report back when I have something to report...

Pelle
/Pelle

Anonymous

  • Guest
Library to header correlation...
« Reply #12 on: January 27, 2005, 12:14:59 pm »
Quote from: "Pelle"
Thank you for the files! I will report back when I have something to report...
Pelle


My pleasure, Pelle.  

(and "reporting back" is hardly necessary  :) )

=======================================
Afterthought...

The more I look at this the more I'm amazed that windows works as well as it does.  Those headers are a tangled up mess of crosslinks and repeated declarations with little or no relationship to the actual code they describe.  Given that Windows is a C code project, I'm given to wonder if the gang at MS really knows what they're doing at all...  

Really... if you're going to make this DLL caled Shell32 why would you name it's header Shelapi?   Or, for that matter, if you're going to create kernel32 why wouldn't you make a Kernel32 header?  That one's spread out across about a half dozen headers...

 :roll: or maybe I was just spoiled by the cleanliness of Pascal units???

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 1974
    • http://www.smorgasbordet.com
Library to header correlation...
« Reply #13 on: January 27, 2005, 02:31:06 pm »
Quote from: "ldblake"
The more I look at this the more I'm amazed that windows works as well as it does.  Those headers are a tangled up mess of crosslinks and repeated declarations with little or no relationship to the actual code they describe.  Given that Windows is a C code project, I'm given to wonder if the gang at MS really knows what they're doing at all...

Looking at the different Windows #include files, even newer ones released about the same time, it seems there must have been a lot of different people/groups involved (some are very clean, while others are a complete mess). I read somewhere recently that much time is spent today just trying to coordinate all the changes. The normal case, when software projects gets too big, I guess. Maybe we should be "happy" it's working at all...

Windows isn't just an operating system anymore, it's grown into somthing much bigger. Not always a good thing...

Pelle
/Pelle

Anonymous

  • Guest
Library to header correlation...
« Reply #14 on: January 27, 2005, 03:45:18 pm »
Quote from: "Pelle"
Looking at the different Windows #include files, even newer ones released about the same time, it seems there must have been a lot of different people/groups involved (some are very clean, while others are a complete mess). I read somewhere recently that much time is spent today just trying to coordinate all the changes. The normal case, when software projects gets too big, I guess. Maybe we should be "happy" it's working at all...

Windows isn't just an operating system anymore, it's grown into somthing much bigger. Not always a good thing...


Ain't that the truth.  I would rather they stuck to the basics... get the multitasker and peripheral IO working to a science... leave the fancy stuff to us application programmer types.  I'm no linux fan by any stretch, but I do have to admire the concept of providing a kernel and letting users and programmers set the direction for the rest.  

The more I climb into windows programming (I'd still be a DOS programmer if I had a choice  :wink: ) the more I find myself wondering what the h_ll they were thinking...  Lets hope the 64bit system isn't just an add-on... it's been a long time since anything truly new came from MS and they're about due.  They've got lots of experience with the concept and the market now... cleaning up the mess and getting their act togeter is just about the only thing they haven't done.

Interestingly, they *could* release a set of cleaned up headers, all done by the same team, without changing the libraries at all.  Why this hasn't been done, we may never know.

Oh well... it is what it is.  The best we can do is try to make it as foolproof as possible  :)