delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/06/27/15:47:52

X-Spam-Check-By: sourceware.org
Message-ID: <4682BEB5.7030304@cygwin.com>
Date: Wed, 27 Jun 2007 15:47:01 -0400
From: "Larry Hall (Cygwin)" <reply-to-list-only-lh AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070505 Remi/2.0.0.0-3.fc4.remi Thunderbird/2.0.0.0 Mnenhy/0.7.5.0
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: How to link with third party libraries using gcc
References: <11331072 DOT post AT talk DOT nabble DOT com>
In-Reply-To: <11331072.post@talk.nabble.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019