Using dlltool to create a .lib for MSVC

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using dlltool to create a .lib for MSVC

Erik de Castro Lopo
Hi all,

I have successfully created a windows DLL using the MinGW Linux to
windows cross compiler tool chain. I have also created a binary that
uses the DLL and it works correctly when run on a windows machine.

However, I have windows users who would like to use my DLL from
programs created using the Microsofts's Visual Studio compiler.
For this they need a file with a .lib extension.

I know this .lib file can be generated using the program lib.exe
which comes with VS and that works fine. However, I also thought it
was possible to use dlltool program from binutils to do the same
thing by doing something like:

    i586-mingw32msvc-dlltool --dllname $dllname --def $defname --output-lib $libname

The lib file created like this seems to be the right file type
(hex dump comparison of this file compared to one generated by
MS's lib.exe), but VS doesn't seem to like it.

Does any one know why? Can this be fixed?

Cheers,
Erik

--
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"You don't have make it your sole purpose in life, but could you at
least sacrifice a rubber chicken upon the altar of literacy?"
 -- TackHead on Slashdot

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dlltool to create a .lib for MSVC

JonY-2
On 11/9/2008 04:52, Erik de Castro Lopo wrote:

> Hi all,
>
> I have successfully created a windows DLL using the MinGW Linux to
> windows cross compiler tool chain. I have also created a binary that
> uses the DLL and it works correctly when run on a windows machine.
>
> However, I have windows users who would like to use my DLL from
> programs created using the Microsofts's Visual Studio compiler.
> For this they need a file with a .lib extension.
>
> I know this .lib file can be generated using the program lib.exe
> which comes with VS and that works fine. However, I also thought it
> was possible to use dlltool program from binutils to do the same
> thing by doing something like:
>
>      i586-mingw32msvc-dlltool --dllname $dllname --def $defname --output-lib $libname
>
> The lib file created like this seems to be the right file type
> (hex dump comparison of this file compared to one generated by
> MS's lib.exe), but VS doesn't seem to like it.
>
> Does any one know why? Can this be fixed?
>
> Cheers,
> Erik
>

Hi,
Can you explain what do you mean by msvc not liking the .a file?

MSVC should be able to link with the library import file without problems.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dlltool to create a .lib for MSVC

Erik de Castro Lopo
JonY wrote:

> Can you explain what do you mean by msvc not liking the .a file?

Unfortunately, I don't have access to MSVC myself so even the info
I have is second hand. This is a report from one of the users of
my library that tried to use the .lib I created with ddltool:

    "I had issues with the files as provided (not sure what wasn't
    working, I only got "unresolved refs" from the linker line
    issued by my project building code.) However, if I used
    Microsoft's lib.exe tool to make my own .lib and .exp files
    from .dll and .def, then it worked fine"

He send me the .lib he created and is about 1/4 of the size of the one
I provided.

I've looked at both files in a hex editor and they are definitely the
same file type, and have similar elements.

> MSVC should be able to link with the library import file without problems.

Ok, so it should work but doesn't.

Cheers,
Erik
--
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"There is no satisfactory substitute for excellence."
-- Dr. Arnold O. Beckman

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dlltool to create a .lib for MSVC

JonY-2
On 11/9/2008 08:29, Erik de Castro Lopo wrote:

> JonY wrote:
>
>> Can you explain what do you mean by msvc not liking the .a file?
>
> Unfortunately, I don't have access to MSVC myself so even the info
> I have is second hand. This is a report from one of the users of
> my library that tried to use the .lib I created with ddltool:
>
>      "I had issues with the files as provided (not sure what wasn't
>      working, I only got "unresolved refs" from the linker line
>      issued by my project building code.) However, if I used
>      Microsoft's lib.exe tool to make my own .lib and .exp files
>      from .dll and .def, then it worked fine"
>

Is it possible for the user to report the list of undefined references?

> He send me the .lib he created and is about 1/4 of the size of the one
> I provided.
>
> I've looked at both files in a hex editor and they are definitely the
> same file type, and have similar elements.
>

What does nm listing say?

>> MSVC should be able to link with the library import file without problems.
>
> Ok, so it should work but doesn't.
>
> Cheers,
> Erik


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dlltool to create a .lib for MSVC

Brian Dessent
In reply to this post by Erik de Castro Lopo
Erik de Castro Lopo wrote:

> I know this .lib file can be generated using the program lib.exe
> which comes with VS and that works fine. However, I also thought it
> was possible to use dlltool program from binutils to do the same
> thing by doing something like:
>
>     i586-mingw32msvc-dlltool --dllname $dllname --def $defname --output-lib $libname

Doing it this way (and apparently, maintaining a .def file by hand) is
the hard way.  You can create the import library as a side effect of
linking the DLL, just add -Wl,--out-implib,filename to your link
command.  You don't need dlltool or a separate step.

The problem with it not working with the MS toolchain is somewhat
independent though -- the import lib generated the tedious way with
dlltool should still be valid.  It could be a number of problems: C++
linkage, different calling conventions, etc.  We need details -- exact
commands and resulting error messages, and ideally a standalone
testcase.

Brian

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dlltool to create a .lib for MSVC

Erik de Castro Lopo
Brian Dessent wrote:

> Doing it this way (and apparently, maintaining a .def file by hand) is
> the hard way.

The DEF file is autogenerated.

> You can create the import library as a side effect of
> linking the DLL, just add -Wl,--out-implib,filename to your link
> command.  You don't need dlltool or a separate step.

Thats good to know. Thanks.

> The problem with it not working with the MS toolchain is somewhat
> independent though -- the import lib generated the tedious way with
> dlltool should still be valid.  It could be a number of problems: C++
> linkage, different calling conventions, etc.  We need details -- exact
> commands and resulting error messages, and ideally a standalone
> testcase.

I tried it myself with an old version of VS2002 (VC7) and wasn't able
to recreate the problem.

Sorry for the noise.

Cheers,
Erik
--
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"There are two kinds of large software systems: those that
evolved from small systems and those that don't work."
-- Seen on slashdot.org, then quoted by amk

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users