X-Spam-Check-By: sourceware.org Message-ID: <11342161.post@talk.nabble.com> Date: Thu, 28 Jun 2007 05:43:11 -0700 (PDT) From: km4hr To: cygwin AT cygwin DOT com Subject: Re: How to link with third party libraries using gcc In-Reply-To: <4682C0EE.D7088ADD@dessent.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: km4hr AT netscape DOT net References: <11331072 DOT post AT talk DOT nabble DOT com> <4682C0EE DOT D7088ADD AT dessent DOT net> X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Brian, It sounds like the solution could range from something as simple as including the ".lib" files on the gcc command line on up to complicated stuff I've never heard of like "decorations", "toolchains", and "calling conventions". I tried the simple suggestion. I copied the ".lib" files to the directory where my program is located. I then entered the following command: gcc myprog.c library1.lib library2.lib -o myprog I got "undefined reference to ..." errors. One for each library function in my program. Next I removed the ".lib" files from the gcc command string as follows: gcc myprog.c -o myprog I got exactly the same errors as I did with the ".lib" files included. Apparently gcc has no idea what the ".lib" files are. Since I have no comprehesion of "decorations", "toolchains", and "calling conventions", or how to find out what that means, I wonder if there's another explanation. I've got a sinking feeling about this. As if I'm going where no man has gone before. Thanks for trying, Brian. I can tell you know what you're talking about. Unfortunately I'm still completely in the dark. Brian Dessent wrote: > > 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: > > libxxx.dll.a > xxx.dll.a > libxxx.a > xxx.lib > cygxxx.dll (*) > libxxx.dll > xxx.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. > > Brian > > -- > 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/ > > > -- View this message in context: http://www.nabble.com/How-to-link-with-third-party-libraries-using-gcc-tf3990417.html#a11342161 Sent from the Cygwin Users mailing list archive at Nabble.com. -- 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/