This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to link with third party libraries using gcc

km4hr wrote:

> I thought Windows shared libraries were indentified by a ".dll" extension.
> However I have a commercial product installed that has a C programming
> interface. It's libraries have a ".lib" extension. I am totally lost as to
> how to link my program to these files.

A .lib file is just an ar archive (.a) file with a different name.  You
can rename it if you want, but you don't have to.  Just give the name of
the file on the link command line.  It should also work to specify -lfoo
to find foo.lib in the search path.  You shouldn't have to futz around
with converting anything or creating a def file, I don't know why the
users guide says any of that (but see below.)

Semantically, a .lib can either be an import library or a static
library; in either case the file format is the same, but in the former
it is an aide for linking against a DLL, in the latter it is just like
static linking on POSIX.  On Cygwin import libraries are typically named
libfoo.dll.a whereas static archives are just named libfoo.a, but this
is just a convention.  Some import libraries are named libfoo.a too, for
example all of w32api.  The ld manual explains the search order for all
these various extensions when you specify -lxxx:

          cygxxx.dll (*)

Note that the last three entail direct-DLL linking without use of an
import library.  Make sure you read the whole win32 section of the ld
manual for details of the significance of this.

What you really have to understand when trying to use these .lib files
is not about filenames or file formats or making .def files or any of
that.  All you really need to determine is: 1) what calling convention
(cdecl or stdcall) does the library use and 2) how are the symbol names
decorated?  Then just make these match with your toolchain.  Usually the
two are related, but they are really separate concepts.  For 1) you have
to get your headers right.  For 2) you create an import library that
contains the necessary aliases, or if your compiler already uses the
same decorations as the library, you can just link against the DLL
directly without an import lib at all.


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]