linking in .lib files

François Gouget fgouget at codeweavers.com
Wed Nov 7 21:11:01 CST 2001


   You cannot use .lib files directly with Winelib. The reason is that
winebuild does not support reading .lib files. Support for '.lib' files
(or possibly even '.dll' files) could be added in but it is not there
currently.
 
   Exactly how you deal with that depends on what your situation:
 1) if you have the sources of the library you want to link with, then
the best solution is to compile it with Winelib too.
 2) if you don't have the sources for this library (and it's not one of
the standard Wine libraries), then you will have to write a stub library
that you will use for just the purpose of linking your application.

   In both cases you will need to create a '.spec' file containing a
list of the functions (with parameters) exported by that library. See
the following URL for a documentation of the exact format of .spec
files:

http://wine.codeweavers.com/docs/winelib-user/spec-file.shtml

Case 1:
   The '.spec' files generated by Winemaker are mostly useful for
compiling applications that just import libraries. When Winemaker
generates the build environment for a library it will not declare the
exported functions in the '.spec' file because it has no knowledge of
which functions are exported. Winemaker could potentially be extended to
generate a list of exported functions when the '.dll' is available by
interfacing it with winedump.
   So if your library only exports a few functions, the easiest solution
is to just declare them manually in the '.spec' file. Otherwise you
should use winedump much as described in case 2, and then copy the .spec
file over to where you compile your library.

Case 2:
   Generating a stub library: the best way to do so is to use winedump.
For that I recommend that you read 'tools/winedump/README' and
especially the section 'Generating stub DLLS'.
   Once you have linked your application with the stub library, it can
run with just the native dll... unless we are talking about a C++
library.
   C++ libraries are troublesome because g++ does not use the same name
mangling as Visual C++ (although maybe g++ 3.0 changed that). So you
will need the stub library to do the bridging. But I am not sure whether
winedump can handle this sort of bridging.


   There is another roadblock that you may hit in both cases: winebuild
does not support importing a variable from another library (because of
ELF limitations). Importing functions is ok, but not variables. This
means that if you are dealing with a C++ library you will need to link
with it in the Unix sense. If we are talking about C code, then there
are ways around it that require only relatively simple code changes. It
is also another reason why you will never be able to use a native C++
library directly (because the virtual table pointers are handled as
variables).

   One last note: specmaker has been folded into winedump recently. So
if you hear/read things about specmaker you know that you have to look
for winedump.


-- 
François Gouget
fgouget at codeweavers.com




More information about the wine-devel mailing list