www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - DLLs/implib

reply bobef <bobef_member pathlink.com> writes:
After spending some time trying to find out how to run GTK+D+Windows (with no
satisfying results) I thought of something... Is it possible to create a tool
that makes headers files out of .lib-s. This would be great... Then we could
just use implib/this tool and boom! And I am not talking only about GTK. Maybe
there is no such tool because it is not possible or because it would be too
easy? I doubt I am the first one to think of it. So what possibly could be the
problems for creating such tool?
Sep 11 2005
next sibling parent reply Sean Kelly <sean f4.ca> writes:
In article <dg1sqq$2ulh$1 digitaldaemon.com>, bobef says...
After spending some time trying to find out how to run GTK+D+Windows (with no
satisfying results) I thought of something... Is it possible to create a tool
that makes headers files out of .lib-s. This would be great... Then we could
just use implib/this tool and boom! And I am not talking only about GTK. Maybe
there is no such tool because it is not possible or because it would be too
easy? I doubt I am the first one to think of it. So what possibly could be the
problems for creating such tool?

To work well, the tool would need to include a full C preprocessor, as C headers tend to include a lot of #defines and #ifdef logic. That aside, I agree that it would be quite useful. Sean
Sep 11 2005
parent reply bobef <bobef lessequal.com> writes:
Sean Kelly wrote:
 In article <dg1sqq$2ulh$1 digitaldaemon.com>, bobef says...
 
After spending some time trying to find out how to run GTK+D+Windows (with no
satisfying results) I thought of something... Is it possible to create a tool
that makes headers files out of .lib-s. This would be great... Then we could
just use implib/this tool and boom! And I am not talking only about GTK. Maybe
there is no such tool because it is not possible or because it would be too
easy? I doubt I am the first one to think of it. So what possibly could be the
problems for creating such tool?

To work well, the tool would need to include a full C preprocessor, as C headers tend to include a lot of #defines and #ifdef logic. That aside, I agree that it would be quite useful. Sean

As much as I know there is no preprocessor in the .lib files... The only thing I want from there is the function declarations... So you can directly use C a DLL. Sounds like a simple tool to me, but I know nothing of the .lib files format...
Sep 11 2005
parent Sean Kelly <sean f4.ca> writes:
In article <dg1vbi$30lb$1 digitaldaemon.com>, bobef says...
As much as I know there is no preprocessor in the .lib files... The only 
thing I want from there is the function declarations... So you can 
directly use C a DLL. Sounds like a simple tool to me, but I know 
nothing of the .lib files format...

My mistake. I thought you wanted to parse the header files of libraries, not the lib files themselves. Sean
Sep 11 2005
prev sibling next sibling parent reply John Reimer <terminal.node gmail.com> writes:
bobef wrote:
 After spending some time trying to find out how to run GTK+D+Windows (with no
 satisfying results) I thought of something... Is it possible to create a tool
 that makes headers files out of .lib-s. This would be great... Then we could
 just use implib/this tool and boom! And I am not talking only about GTK. Maybe
 there is no such tool because it is not possible or because it would be too
 easy? I doubt I am the first one to think of it. So what possibly could be the
 problems for creating such tool?
 
 

This has been discussed. I think everybody wants such a tool, and it is technically possible, I believe... although it seems that without some specialized optimization such a tool would slow compilation down significantly because of repeated lib parsing. Still, I've been waiting for this kind of tool to appear so that we can say D trully has headerless capabilities. That said, you might like to have a look at dynDUI's lib\Loader.d module (along with all the gtk modules in that directory). It loads symbols from the gtk dll's dynamically for both windows and linux so that you don't have to worry about linking with the gtk libraries. It works well as long as you have the dll's installed. The only drawback currently is that it doesn't include all gtk symbols yet. But those are easy to add on an "as needed" basis. -JJR
Sep 11 2005
parent bobef <bobef lessequal.com> writes:
John Reimer wrote:

 
 This has been discussed.  I think everybody wants such a tool, and it is 
 technically possible, I believe... although it seems that without some 
 specialized optimization such a tool would slow compilation down 
 significantly because of repeated lib parsing.  Still, I've been waiting 
 for this kind of tool to appear so that we can say D trully has 
 headerless capabilities.
 

I can't see how it can slow down anything. I see it this way: 1. download latest precompiled C DLL for GTK or whatever 2. use implib to get libraries out of it 3. use the new tool to get module with function declarations from the libraries 4. import the module and enjoy No repeated lib parsing or whatever. It will be repeated only when they make new versions...
 That said, you might like to have a look at dynDUI's lib\Loader.d module 
 (along with all the gtk modules in that directory).  It loads symbols 
 from the gtk dll's dynamically for both windows and linux so that you 
 don't have to worry about linking with the gtk libraries.  It works well 
 as long as you have the dll's installed.  The only drawback currently is 
 that it doesn't include all gtk symbols yet.  But those are easy to add 
 on an "as needed" basis.

Thanks. I'll have a look...
Sep 11 2005
prev sibling next sibling parent "Charles" <noone nowhere.com> writes:
Yea that would be sweet , I know pragma has been working on something
similar with object files : http://www.dsource.org/forums/viewforum.php?f=70

Charlie

"bobef" <bobef_member pathlink.com> wrote in message
news:dg1sqq$2ulh$1 digitaldaemon.com...
 After spending some time trying to find out how to run GTK+D+Windows (with

 satisfying results) I thought of something... Is it possible to create a

 that makes headers files out of .lib-s. This would be great... Then we

 just use implib/this tool and boom! And I am not talking only about GTK.

 there is no such tool because it is not possible or because it would be

 easy? I doubt I am the first one to think of it. So what possibly could be

 problems for creating such tool?

Sep 11 2005
prev sibling parent reply pragma <EricAnderton youknowthedrill.yahoo> writes:
bobef wrote:
 After spending some time trying to find out how to run GTK+D+Windows (with no
 satisfying results) I thought of something... Is it possible to create a tool
 that makes headers files out of .lib-s. This would be great... Then we could
 just use implib/this tool and boom! And I am not talking only about GTK. Maybe
 there is no such tool because it is not possible or because it would be too
 easy? I doubt I am the first one to think of it. So what possibly could be the
 problems for creating such tool?
 
 

DDL has support for gathering symbolic information from OMF .obj and .lib files. COFF support is on the way, and ELF support is planned in the near future. http://www.dsource.org/projects/ddl I am putting the final polish on the symbol demangler (based on James' code BTW) which will be released along with a rather sizable batch of improvements to this library. However, its all in a very raw state for the time being. I'd imagine that with the demangler code in place, you'll be practically home free. Heck, I may even make a stab at a header generator myself. -- - EricAnderton at yahoo
Sep 11 2005
parent reply John Reimer <terminal.node gmail.com> writes:
pragma wrote:
 bobef wrote:
 
 After spending some time trying to find out how to run GTK+D+Windows 
 (with no
 satisfying results) I thought of something... Is it possible to create 
 a tool
 that makes headers files out of .lib-s. This would be great... Then we 
 could
 just use implib/this tool and boom! And I am not talking only about 
 GTK. Maybe
 there is no such tool because it is not possible or because it would 
 be too
 easy? I doubt I am the first one to think of it. So what possibly 
 could be the
 problems for creating such tool?

DDL has support for gathering symbolic information from OMF .obj and .lib files. COFF support is on the way, and ELF support is planned in the near future. http://www.dsource.org/projects/ddl I am putting the final polish on the symbol demangler (based on James' code BTW) which will be released along with a rather sizable batch of improvements to this library. However, its all in a very raw state for the time being. I'd imagine that with the demangler code in place, you'll be practically home free. Heck, I may even make a stab at a header generator myself.

Eric... this is great, but I'm wondering how this works for c-based libs. How do you get the parameter details for the functions? D based functions are easy since the parameter typs are mangled into the symbol name. I'm just curious how this will work for C-base libraries. -JJR
Sep 11 2005
parent reply pragma <EricAnderton youknowthedrill.yahoo> writes:
John Reimer wrote:
 
 Eric... this is great, but I'm wondering how this works for c-based 
 libs.  How do you get the parameter details for the functions?  D based 
 functions are easy since the parameter typs are mangled into the symbol 
 name.  I'm just curious how this will work for C-base libraries.

In short, it won't. Walter was nice enough to give D's symbol mangling some smarts so that function overloading works correctly. As for C functions, the best that can be done (for a header generator) is to emit a file that simply has them declared as something like this:
 extern(C) void* foobar; //TODO: change me (this means you)

Which is a far cry from what we want, but is just about all you're going to get from the perspective of an .obj or .lib file. When you get down to it, the DDL suite is really tailored for mostly pure D code and binary data, so it's not a perfect fit here. For this case, I think the future will probably hold a special place for something that can parse .c and .h files to generate D symbol files. Its either that or we improve the current batch of .h to .d conversion utils. -- - EricAnderton at yahoo
Sep 11 2005
next sibling parent reply bobef <bobef lessequal.com> writes:
pragma wrote:
 John Reimer wrote:
 
 Eric... this is great, but I'm wondering how this works for c-based 
 libs.  How do you get the parameter details for the functions?  D 
 based functions are easy since the parameter typs are mangled into the 
 symbol name.  I'm just curious how this will work for C-base libraries.

In short, it won't. Walter was nice enough to give D's symbol mangling some smarts so that function overloading works correctly. As for C functions, the best that can be done (for a header generator) is to emit a file that simply has them declared as something like this: > extern(C) void* foobar; //TODO: change me (this means you) Which is a far cry from what we want, but is just about all you're going to get from the perspective of an .obj or .lib file. When you get down to it, the DDL suite is really tailored for mostly pure D code and binary data, so it's not a perfect fit here. For this case, I think the future will probably hold a special place for something that can parse .c and .h files to generate D symbol files. Its either that or we improve the current batch of .h to .d conversion utils.

I found an article where they did it for C++. http://www.newlc.com/article.php3?id_article=530 The example was using nm from binutils but it requires COFF format and I couldn't manage to convert OMF to COFF. And if I did I am still not sure it would work. I don't know. Take a look. Maybe it will mean something more for you than me.
Sep 12 2005
parent J Thomas <jtd514 ameritech.net> writes:
the difference is C++ has all the identifiers mangled to bake in the 
types and arguments, whereas in c all we get are function names. Ive got 
windows COFF code but unfortunately I dont see how this is really going 
to help for C modules. as eric said all you would produce is a list of 
function names.

bobef wrote:
 pragma wrote:
 
 John Reimer wrote:

 Eric... this is great, but I'm wondering how this works for c-based 
 libs.  How do you get the parameter details for the functions?  D 
 based functions are easy since the parameter typs are mangled into 
 the symbol name.  I'm just curious how this will work for C-base 
 libraries.

In short, it won't. Walter was nice enough to give D's symbol mangling some smarts so that function overloading works correctly. As for C functions, the best that can be done (for a header generator) is to emit a file that simply has them declared as something like this: > extern(C) void* foobar; //TODO: change me (this means you) Which is a far cry from what we want, but is just about all you're going to get from the perspective of an .obj or .lib file. When you get down to it, the DDL suite is really tailored for mostly pure D code and binary data, so it's not a perfect fit here. For this case, I think the future will probably hold a special place for something that can parse .c and .h files to generate D symbol files. Its either that or we improve the current batch of .h to .d conversion utils.

I found an article where they did it for C++. http://www.newlc.com/article.php3?id_article=530 The example was using nm from binutils but it requires COFF format and I couldn't manage to convert OMF to COFF. And if I did I am still not sure it would work. I don't know. Take a look. Maybe it will mean something more for you than me.

Sep 12 2005
prev sibling parent kai <digitalmars kaishaku.org> writes:
On Sun, 11 Sep 2005 19:09:04 -0700, pragma
<EricAnderton youknowthedrill.yahoo> wrote:

John Reimer wrote:
 
 Eric... this is great, but I'm wondering how this works for c-based 
 libs.  How do you get the parameter details for the functions?  D based 
 functions are easy since the parameter typs are mangled into the symbol 
 name.  I'm just curious how this will work for C-base libraries.

In short, it won't. Walter was nice enough to give D's symbol mangling some smarts so that function overloading works correctly. As for C functions, the best that can be done (for a header generator) is to emit a file that simply has them declared as something like this:
 extern(C) void* foobar; //TODO: change me (this means you)

Which is a far cry from what we want, but is just about all you're going to get from the perspective of an .obj or .lib file. When you get down to it, the DDL suite is really tailored for mostly pure D code and binary data, so it's not a perfect fit here. For this case, I think the future will probably hold a special place for something that can parse .c and .h files to generate D symbol files. Its either that or we improve the current batch of .h to .d conversion utils.

Someone should add D support to SWIG. This will allow us to make D wrappers of C and C++ libraries easily. http://www.swig.org/ The Java or C# implementations might provide decent reference. I just posted an ideal, but related, solution a few minutes ago. -- kai
Jan 24 2006