Re: gcc: How does gcc look for foo.dll in `gcc ... -lfoo'?

2004-07-13 Thread Gerrit P. Haase
Alexey wrote:

 I'm confused since the gcc documentation says that the only thing that
 `-lfoo' does, is that it allows gcc to look for `libfoo.a' while linking.
 But what about the shared libraries (DLLs)? It seems to me that gcc looks
 for `libfoo.dll', `cygfoo.dll', `foo.dll' and may be for all these plus `.a'
 suffix, doesn't it? But, for example, libfoo and cygfoo could be two
 _different_ libraries at all. Can anybody explain the -l feature for DLLs?
 I've tried the Cygwin's User Guide and gcc info, but did not find any
 answer.
Given you have a library 'mfoo', then you should have a file libmfoo.a
in /usr/lib which is the static archive in the default search path.  you
specify this archive at the gcc link command with -lmfoo, if this
library is a shared library, you should have also an import library
/usr/lib/libmfoo.dll.a and a DLL /usr/bin/cygmfoo-2.dll, the default
search order is /usr/lib, /usr/bin and then libmfoo.dll.a, libmfoo.a,
cygmfoo.dll. 

So if you have just a static archive, it is found, if you have an import
library and a static archive at first the import library is used (if
not -static is used at the link command).  If the import library is
used, ld knows how to find the correct DLL and links the application
against the DLL using the import library.   If there is no static
archive and no import library, then also /usr/bin is searched and also
the cygmfoo.dll would be found, but if its actual name is cygmfoo/2.dll
you would need to specify -lmfoo-2 at the link line to succeed the
direct linking with the DLL.

Additionally you may specify the full name with path to link against:

gcc -o myapp.exe main_object.o /usr/lib/libmfoo.dll.a
or
gcc -o myapp.exe main_object.o /usr/lib/libmfoo.a
or
gcc -o myapp.exe main_object.o /usr/bin/cygmfoo-2.dll


Gerrit
-- 
=^..^= http://nyckelpiga.de/donate.html


--
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/



Re: gcc: How does gcc look for foo.dll in `gcc ... -lfoo'?

2004-07-13 Thread Charles Wilson
Gerrit P. Haase wrote:
Alexey wrote:

I'm confused since the gcc documentation says that the only thing that
`-lfoo' does, is that it allows gcc to look for `libfoo.a' while linking.
But what about the shared libraries (DLLs)? It seems to me that gcc looks
for `libfoo.dll', `cygfoo.dll', `foo.dll' and may be for all these plus `.a'
suffix, doesn't it? But, for example, libfoo and cygfoo could be two
_different_ libraries at all. Can anybody explain the -l feature for DLLs?
I've tried the Cygwin's User Guide and gcc info, but did not find any
answer.
Given you have a library 'mfoo', then you should have a file libmfoo.a
in /usr/lib which is the static archive in the default search path.  you
specify this archive at the gcc link command with -lmfoo, if this
library is a shared library, you should have also an import library
/usr/lib/libmfoo.dll.a and a DLL /usr/bin/cygmfoo-2.dll, the default
search order is /usr/lib, /usr/bin and then libmfoo.dll.a, libmfoo.a,
cygmfoo.dll. 

So if you have just a static archive, it is found, if you have an import
library and a static archive at first the import library is used (if
not -static is used at the link command).  If the import library is
used, ld knows how to find the correct DLL and links the application
against the DLL using the import library.   If there is no static
archive and no import library, then also /usr/bin is searched and also
the cygmfoo.dll would be found, but if its actual name is cygmfoo/2.dll
you would need to specify -lmfoo-2 at the link line to succeed the
direct linking with the DLL.
Additionally you may specify the full name with path to link against:
gcc -o myapp.exe main_object.o /usr/lib/libmfoo.dll.a
or
gcc -o myapp.exe main_object.o /usr/lib/libmfoo.a
or
gcc -o myapp.exe main_object.o /usr/bin/cygmfoo-2.dll
Don't forget the -static option, which forces the compiler to ignore 
lib*.dll.a and cyg*.dll.

All of this is documented in the linker's documentation.  Do 'info ld'
--
Chuck
--
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/


Re: gcc: How does gcc look for foo.dll in `gcc ... -lfoo'?

2004-07-13 Thread Alexey Lyubimov
Thank you, Gerrit!
It is almost clear now (thanks to Charles Wilson too!). But there are two
things left:
1) Why does the linker searches not only for libmfoo... libraries, but for
mfoo.dll itself (without any lib or cyg prefix) also?
2) What are the pros  cons of using import library and linking against the
shared library directly, I mean, what is the difference between
gcc -o myapp.exe main_object.o /usr/lib/libmfoo.dll.a
and
gcc -o myapp.exe main_object.o /usr/bin/cygmfoo.dll

Thank you, Alexey

- Original Message -
From: Gerrit P. Haase [EMAIL PROTECTED]
To: Alexey Lyubimov [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Tuesday, July 13, 2004 9:00 PM
Subject: Re: gcc: How does gcc look for foo.dll in `gcc ... -lfoo'?


 Alexey wrote:

  I'm confused since the gcc documentation says that the only thing that
  `-lfoo' does, is that it allows gcc to look for `libfoo.a' while
linking.
  But what about the shared libraries (DLLs)? It seems to me that gcc
looks
  for `libfoo.dll', `cygfoo.dll', `foo.dll' and may be for all these plus
`.a'
  suffix, doesn't it? But, for example, libfoo and cygfoo could be two
  _different_ libraries at all. Can anybody explain the -l feature for
DLLs?
  I've tried the Cygwin's User Guide and gcc info, but did not find any
  answer.
 Given you have a library 'mfoo', then you should have a file libmfoo.a
 in /usr/lib which is the static archive in the default search path.  you
 specify this archive at the gcc link command with -lmfoo, if this
 library is a shared library, you should have also an import library
 /usr/lib/libmfoo.dll.a and a DLL /usr/bin/cygmfoo-2.dll, the default
 search order is /usr/lib, /usr/bin and then libmfoo.dll.a, libmfoo.a,
 cygmfoo.dll.

 So if you have just a static archive, it is found, if you have an import
 library and a static archive at first the import library is used (if
 not -static is used at the link command).  If the import library is
 used, ld knows how to find the correct DLL and links the application
 against the DLL using the import library.   If there is no static
 archive and no import library, then also /usr/bin is searched and also
 the cygmfoo.dll would be found, but if its actual name is cygmfoo/2.dll
 you would need to specify -lmfoo-2 at the link line to succeed the
 direct linking with the DLL.

 Additionally you may specify the full name with path to link against:

 gcc -o myapp.exe main_object.o /usr/lib/libmfoo.dll.a
 or
 gcc -o myapp.exe main_object.o /usr/lib/libmfoo.a
 or
 gcc -o myapp.exe main_object.o /usr/bin/cygmfoo-2.dll


 Gerrit
 --
 =^..^=
http://nyckelpiga.de/donate.html



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.719 / Virus Database: 475 - Release Date: 12.07.04


--
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/