* how could make gcc link static library default? @ 2013-10-17 3:40 net_robber 2013-10-17 4:21 ` Anandkumar, CB IN BLR STS 0 siblings, 1 reply; 11+ messages in thread From: net_robber @ 2013-10-17 3:40 UTC (permalink / raw) To: gcc-help 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? ^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: how could make gcc link static library default? 2013-10-17 3:40 how could make gcc link static library default? net_robber @ 2013-10-17 4:21 ` Anandkumar, CB IN BLR STS 2013-10-17 4:38 ` Terry Guo 0 siblings, 1 reply; 11+ messages in thread From: Anandkumar, CB IN BLR STS @ 2013-10-17 4:21 UTC (permalink / raw) To: net_robber, gcc-help 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. 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? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how could make gcc link static library default? 2013-10-17 4:21 ` Anandkumar, CB IN BLR STS @ 2013-10-17 4:38 ` Terry Guo 2013-10-17 5:06 ` Anandkumar, CB IN BLR STS 0 siblings, 1 reply; 11+ messages in thread From: Terry Guo @ 2013-10-17 4:38 UTC (permalink / raw) To: Anandkumar, CB IN BLR STS; +Cc: net_robber, gcc-help 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? ^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: how could make gcc link static library default? 2013-10-17 4:38 ` Terry Guo @ 2013-10-17 5:06 ` Anandkumar, CB IN BLR STS 2013-10-17 5:48 ` Terry Guo 0 siblings, 1 reply; 11+ messages in thread From: Anandkumar, CB IN BLR STS @ 2013-10-17 5:06 UTC (permalink / raw) To: flameroc; +Cc: net_robber, gcc-help 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? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how could make gcc link static library default? 2013-10-17 5:06 ` Anandkumar, CB IN BLR STS @ 2013-10-17 5:48 ` Terry Guo 2013-10-17 6:39 ` net_robber 0 siblings, 1 reply; 11+ messages in thread From: Terry Guo @ 2013-10-17 5:48 UTC (permalink / raw) To: Anandkumar, CB IN BLR STS; +Cc: net_robber, gcc-help On Thu, Oct 17, 2013 at 1:05 PM, Anandkumar, CB IN BLR STS <anand.cb@siemens.com> wrote: > Hi Terry, > Normally dynamic is given more preference over static so this should work. > Got your point. Thanks. BR, Terry > 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? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how could make gcc link static library default? 2013-10-17 5:48 ` Terry Guo @ 2013-10-17 6:39 ` net_robber 2013-10-17 6:52 ` Anandkumar, CB IN BLR STS 0 siblings, 1 reply; 11+ messages in thread From: net_robber @ 2013-10-17 6:39 UTC (permalink / raw) To: Terry Guo; +Cc: Anandkumar, CB IN BLR STS, gcc-help thanks for your share, but this is can be use in case you know what type of the library is. could it be done by gcc auto?? On Thu, Oct 17, 2013 at 1:48 PM, Terry Guo <flameroc@gmail.com> wrote: > On Thu, Oct 17, 2013 at 1:05 PM, Anandkumar, CB IN BLR STS > <anand.cb@siemens.com> wrote: >> Hi Terry, >> Normally dynamic is given more preference over static so this should work. >> > > Got your point. Thanks. > > BR, > Terry > >> 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? ^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: how could make gcc link static library default? 2013-10-17 6:39 ` net_robber @ 2013-10-17 6:52 ` Anandkumar, CB IN BLR STS 2013-10-17 6:58 ` net_robber 0 siblings, 1 reply; 11+ messages in thread From: Anandkumar, CB IN BLR STS @ 2013-10-17 6:52 UTC (permalink / raw) To: net_robber, flameroc; +Cc: gcc-help Hi Terry, I agree that below mentioned step is needed when you are aware of type of library and this is need for interlinking static and dynamic library. But for the scenario you mentioned below then existing mechanism will do the trick. For example you have library named libfoo.so and libfoo.a in folder named /usr/lib/custom/ and you compile you program test.c to use this library. gcc -o test test.c -lfoo -L/usr/lib/custom Then first priority is given for dynamic in case dynamic does not exist it uses static. With Regards, Anand -----Original Message----- From: net_robber [mailto:net_robber@timectrl.net] Sent: Thursday, October 17, 2013 12:09 PM To: Terry Guo Cc: Anandkumar, CB IN BLR STS; gcc-help@gcc.gnu.org Subject: Re: how could make gcc link static library default? thanks for your share, but this is can be use in case you know what type of the library is. could it be done by gcc auto?? On Thu, Oct 17, 2013 at 1:48 PM, Terry Guo <flameroc@gmail.com> wrote: > On Thu, Oct 17, 2013 at 1:05 PM, Anandkumar, CB IN BLR STS > <anand.cb@siemens.com> wrote: >> Hi Terry, >> Normally dynamic is given more preference over static so this should work. >> > > Got your point. Thanks. > > BR, > Terry > >> 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? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how could make gcc link static library default? 2013-10-17 6:52 ` Anandkumar, CB IN BLR STS @ 2013-10-17 6:58 ` net_robber 2013-10-17 9:04 ` Andrew Haley 0 siblings, 1 reply; 11+ messages in thread From: net_robber @ 2013-10-17 6:58 UTC (permalink / raw) To: Anandkumar, CB IN BLR STS; +Cc: flameroc, gcc-help how to make it the first priority give to static, and then, in case static does not exist it uses dynamic. On Thu, Oct 17, 2013 at 2:50 PM, Anandkumar, CB IN BLR STS <anand.cb@siemens.com> wrote: > Hi Terry, > I agree that below mentioned step is needed when you are aware of type of library and this is need for interlinking static and dynamic library. But for the scenario you mentioned below then existing mechanism will do the trick. For example you have library named libfoo.so and libfoo.a in folder named /usr/lib/custom/ and you compile you program test.c to use this library. > > gcc -o test test.c -lfoo -L/usr/lib/custom > > Then first priority is given for dynamic in case dynamic does not exist it uses static. > > With Regards, > Anand > > -----Original Message----- > From: net_robber [mailto:net_robber@timectrl.net] > Sent: Thursday, October 17, 2013 12:09 PM > To: Terry Guo > Cc: Anandkumar, CB IN BLR STS; gcc-help@gcc.gnu.org > Subject: Re: how could make gcc link static library default? > > thanks for your share, > but this is can be use in case you know what type of the library is. > could it be done by gcc auto?? > > On Thu, Oct 17, 2013 at 1:48 PM, Terry Guo <flameroc@gmail.com> wrote: >> On Thu, Oct 17, 2013 at 1:05 PM, Anandkumar, CB IN BLR STS >> <anand.cb@siemens.com> wrote: >>> Hi Terry, >>> Normally dynamic is given more preference over static so this should work. >>> >> >> Got your point. Thanks. >> >> BR, >> Terry >> >>> 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? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how could make gcc link static library default? 2013-10-17 6:58 ` net_robber @ 2013-10-17 9:04 ` Andrew Haley 2013-10-17 9:11 ` net_robber 0 siblings, 1 reply; 11+ messages in thread From: Andrew Haley @ 2013-10-17 9:04 UTC (permalink / raw) To: net_robber; +Cc: Anandkumar, CB IN BLR STS, flameroc, gcc-help On 10/17/2013 07:57 AM, net_robber wrote: > how to make it the first priority give to static, and then, in case > static does not exist it uses dynamic. Have a look at /usr/lib/libc.so on a GNU/Linux system of your choice. Here it is on mine: /* GNU ld script Use the shared library, but some functions are only in the static library, so try that secondarily. */ OUTPUT_FORMAT(elf32-i386) GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.2 ) ) Andrew. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how could make gcc link static library default? 2013-10-17 9:04 ` Andrew Haley @ 2013-10-17 9:11 ` net_robber 2013-10-17 10:42 ` Andrew Haley 0 siblings, 1 reply; 11+ messages in thread From: net_robber @ 2013-10-17 9:11 UTC (permalink / raw) To: Andrew Haley; +Cc: Anandkumar, CB IN BLR STS, flameroc, gcc-help how to get that information On Thu, Oct 17, 2013 at 5:04 PM, Andrew Haley <aph@redhat.com> wrote: > On 10/17/2013 07:57 AM, net_robber wrote: >> how to make it the first priority give to static, and then, in case >> static does not exist it uses dynamic. > > Have a look at /usr/lib/libc.so on a GNU/Linux system of your choice. > > Here it is on mine: > > /* GNU ld script > Use the shared library, but some functions are only in > the static library, so try that secondarily. */ > OUTPUT_FORMAT(elf32-i386) > GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.2 ) ) > > Andrew. > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how could make gcc link static library default? 2013-10-17 9:11 ` net_robber @ 2013-10-17 10:42 ` Andrew Haley 0 siblings, 0 replies; 11+ messages in thread From: Andrew Haley @ 2013-10-17 10:42 UTC (permalink / raw) To: net_robber; +Cc: Anandkumar, CB IN BLR STS, flameroc, gcc-help On 10/17/2013 10:11 AM, net_robber wrote: > how to get that information Please don't top-post on the GCC lists. I don't understand your question. What does "how to get that information" mean? It's in the file /usr/lib/libc.so. > On Thu, Oct 17, 2013 at 5:04 PM, Andrew Haley <aph@redhat.com> wrote: >> On 10/17/2013 07:57 AM, net_robber wrote: >>> how to make it the first priority give to static, and then, in case >>> static does not exist it uses dynamic. >> >> Have a look at /usr/lib/libc.so on a GNU/Linux system of your choice. >> >> Here it is on mine: >> >> /* GNU ld script >> Use the shared library, but some functions are only in >> the static library, so try that secondarily. */ >> OUTPUT_FORMAT(elf32-i386) >> GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.2 ) ) >> >> Andrew. >> ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-10-17 10:42 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2013-10-17 3:40 how could make gcc link static library default? net_robber 2013-10-17 4:21 ` Anandkumar, CB IN BLR STS 2013-10-17 4:38 ` Terry Guo 2013-10-17 5:06 ` Anandkumar, CB IN BLR STS 2013-10-17 5:48 ` Terry Guo 2013-10-17 6:39 ` net_robber 2013-10-17 6:52 ` Anandkumar, CB IN BLR STS 2013-10-17 6:58 ` net_robber 2013-10-17 9:04 ` Andrew Haley 2013-10-17 9:11 ` net_robber 2013-10-17 10:42 ` Andrew Haley
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).