[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: library search test fails, please help
From: |
Keith Marshall |
Subject: |
Re: library search test fails, please help |
Date: |
Mon, 23 Feb 2009 09:42:19 +0000 |
User-agent: |
KMail/1.9.10 |
On Monday 23 February 2009 01:39:52 Allan Caffee wrote:
> Indeed I tried a very similiar scenario using gcc 4.2.4 on Ubuntu
> (with a static library) and had the same problem.
Unsurprising, since you have specified your g++ command incorrectly.
> Was the error similiar to your original post? A linker error? We
> must be missing something pretty obvious here.
You are -- *user* error! You gave an example of g++ usage, which was
effectively equivalent to:
$ g++ -L /path/to/my/libs -lbar foo.cpp
This is just plain wrong. You are asking ld (indirectly) to search in
libbar.a, for any symbols to satisfy any dependencies it has already
identified, AT THE TIME WHEN IT SCANS THE LIBRARY. Since arguments
to ld are processed in strictly left to right order, there are no
such symbol dependencies at this time; (the dependencies will not be
discovered until *after* foo.cpp has been processed, and that happens
too late to fetch in *anything* from libbar.a, so libbar.a becomes
effectively unused, in this scenario. You *must* specify your source
or simple object files, *before* any library you wish to search for
symbols used by them. Thus, the correct usage is:
$ g++ foo.cpp -L /path/to/my/libs -lbar
This illustrates a very common user error, and many users complain
that ld must be broken, when they commit it. This is particularly
true of users coming from GNU/Linux to MS-Win32 development, because
they have developed a *bad* *habit* on GNU/Linux; when linking to a
*shared* object library, the misplacement of the library spec may be
forgiven by the ELF gnu-ld, but it is still an error, and it will be
severely punished by the PE-COFF gnu-ld on MS-Win32. In the case of
*static* libraries, this error will also be punished on GNU/Linux,
just as it is on MS-Win32.
On the gcc, or g++ command line, libraries *must* *always* be
specified *after* the source or object files which refer to them.
--
Regards,
Keith.
- library search test fails, please help, aaragon, 2009/02/21
- Re: library search test fails, please help, Allan Caffee, 2009/02/22
- Re: library search test fails, please help, Thomas Dickey, 2009/02/22
- Re: library search test fails, please help, aaragon, 2009/02/22
- Re: library search test fails, please help, aaragon, 2009/02/22
- Re: library search test fails, please help, Bob Friesenhahn, 2009/02/22
- Re: library search test fails, please help, aaragon, 2009/02/22
- Re: library search test fails, please help, Allan Caffee, 2009/02/22
- Re: library search test fails, please help,
Keith Marshall <=
Re: library search test fails, please help, Duane Ellis, 2009/02/22
Re: library search test fails, please help, Peter O'Gorman, 2009/02/22
- Re: library search test fails, please help, aaragon, 2009/02/22
- Re: library search test fails, please help, Peter Johansson, 2009/02/22
- Message not available
- Re: library search test fails, please help, Peter Johansson, 2009/02/23
- RE: library search test fails, please help, John Calcote, 2009/02/23
- Re: library search test fails, please help, aaragon, 2009/02/23
- Re: library search test fails, please help, aaragon, 2009/02/23
Re: library search test fails, please help, Keith Marshall, 2009/02/23