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 do a fair amount of C programming on Unix but almost none on Windows. I
know almost nothing about Windows libraries. I'd be happy if I never had to
deal with them at all. But I have a need.


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.

The Cygwin User's Guide contains an extremely brief section on linking
against DLL's (section 4.3.2). It shows how to use "nm" to create a  ".def"
file and then "dlltool" to create a ".a" file. I don't know how this relates
to the ".lib" files that I have.

The command given in the User's Guide create the ".def" file is as follows:

nm foo.dll | grep ' T _' | sed 's/.* T _//' >> foo.def

I don't have a ".dll" file but I noticed that my ".lib" files have lines
containing the string " T _" .  So I ran the above "nm" command using my
".lib" files. The resulting ".def" file won't work with the second step
which is:

dlltool --def foo.def --dllname foo.dll --output-lib foo.a

The error I get from the above command says that the ".def" file has
incorrect format.

In summary, I'm totally lost. I have no idea what's going on here. Does any
of this make sense to you guys.? Can you tell me how to link against a
".lib" file?


You should read up on Windows DLLs.  Check out the MSDN for more info.
Windows has static libraries just like Unix/Linux does.  So your '.lib'
may be a static lib.  You can typically tell if there is only a '.lib'
and not a like-named '.dll'.  If yoou have both, then the '.lib' is an
"import library".  That's what Windows uses to resolve all symbols at
link time (again, see Windows docs for more detail).

You should be able to link against the '.lib' rather directly if you want
to build with Cygwin.  Rename 'foo.lib' as 'libfoo.a' and link to it with
'-lfoo' just like in Unix/Linux.  Of course, if the API you're using is
C++, you're stuck using the compiler that the vendor compiled the libs/dlls
with.


-- Larry Hall http://www.rfk.com RFK Partners, Inc. (508) 893-9779 - RFK Office 216 Dalton Rd. (508) 893-9889 - FAX Holliston, MA 01746

_____________________________________________________________________

A: Yes.
> Q: Are you sure?
>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top posting annoying in email?

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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