This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: how could make gcc link static library default?
- From: "Anandkumar, CB IN BLR STS" <anand dot cb at siemens dot com>
- To: "flameroc at gmail dot com" <flameroc at gmail dot com>
- Cc: "net_robber at timectrl dot net" <net_robber at timectrl dot net>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 17 Oct 2013 10:35:39 +0530
- Subject: RE: how could make gcc link static library default?
- Authentication-results: sourceware.org; auth=none
- References: <CACdxSLm=7+1vPyQBHE7+xutvdxbz-SaHz37VsCtsc9=VmFvS-w at mail dot gmail dot com> <80070575041F1A43B43673DA71C5B0BCBBE2B2EBBC at INBLRK77M1MSX dot in002 dot siemens dot net> <CAGbRaL6GirQ-nQT59=HTHUc5fipqwtXq+XYxVq5n2ayZ9oo7Jg at mail dot gmail dot com>
Hi Terry,
Normally dynamic is given more preference over static so this should work.
With Regards,
Anand
-----Original Message-----
From: Terry Guo [mailto:flameroc@gmail.com]
Sent: Thursday, October 17, 2013 10:09 AM
To: Anandkumar, CB IN BLR STS
Cc: net_robber@timectrl.net; gcc-help@gcc.gnu.org
Subject: Re: how could make gcc link static library default?
On Thu, Oct 17, 2013 at 12:21 PM, Anandkumar, CB IN BLR STS <anand.cb@siemens.com> wrote:
> Hi,
> You try both static and dynamic linking with following options with example mentioned below:
> If you have want to compile a program test.c which is dependent on 2 static library foo1 and foo2 and one dynamic library foo3 then below mentioned command will do the trick.
>
> gcc test.c -W1,-Bstatic -lfoo1 -lfoo2 -W1,-Bdynamic -lfoo3 -o
> test
>
>
> Try this trick on any number of static and dynamic libraries.
Thanks for sharing and sorry for interrupting. I am thinking another similar scenario: sometimes the foo3 exists in dynamic library, sometimes it exists in static library. Is it possible to let gcc search the dynamic one first and then search the static one if dynamic doesn't exist? Does command like below works?
gcc test.c -Wl,-Bdynamic -lfoo3 -Wl,-Bstatic -lfoo3 -o test
And if both dynamic one and static exist, is it possible to let gcc choose the dynamic one over the static one or choose the static one over the dynamic one? Thanks.
BR,
Terry
>
> With Regards,
> Anand
>
> -----Original Message-----
> From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org]
> On Behalf Of net_robber
> Sent: Thursday, October 17, 2013 9:10 AM
> To: gcc-help@gcc.gnu.org
> Subject: how could make gcc link static library default?
>
> hi,
>
> i know a option -static to force gcc link static library, which will ignore shared library.
> but in my case, some library just have shared library.
> so, is want gcc linlk static library first, then shared library if
> static one was not found
>
> how to do that?