How to link system libraries(libc.so, libpthread.so) in dynamic way and others in static?

  • Follow


Hi forks,

   I would like to link some  my own libraries in static way.
   Also, linking system libraries such as libc.so and libpthread.so in
dynamic.
  How do I archive this without using -static flag?

BR,
Chisin

0
Reply chisin.lin (3) 9/11/2007 2:33:47 AM

Chisin <chisin.lin@msa.hinet.net> writes:

>    I would like to link some  my own libraries in static way.
>    Also, linking system libraries such as libc.so and libpthread.so in
> dynamic. How do I archive this without using -static flag?

This is system-specific. On Linux, Solaris, and possibly others:

  cc main.o ... -Wl,-Bstatic -lmylib -lotherlib -Wl,-Bdynamic -lpthread

Alternatively,

  cc main.o /path/to/libmylib.a /path/to/libotherlib.a -lpthread

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
0
Reply ppluzhnikov-nsp (516) 9/11/2007 3:13:40 AM


On 2007-09-11, Chisin <chisin.lin@msa.hinet.net> wrote:
>
>    I would like to link some  my own libraries in static way.
>    Also, linking system libraries such as libc.so and libpthread.so in
> dynamic.
>   How do I archive this without using -static flag?

Just include your libraries' files in the linking command:
$ cc -o mybin libfoo.a libbar.a -lphthreads -lm

However that doesn't look into /usr/lib or whatever for libfoo and
libbar, so it's only practical if you have them within a single build
tree and know their relative paths.

-- 
John Tsiombikas (Nuclear / Mindlapse)
nuclear@siggraph.org
http://nuclear.demoscene.gr/
0
Reply nuclear (91) 9/11/2007 1:40:31 PM

2 Replies
49 Views

(page loaded in 0.055 seconds)

Similiar Articles:




7/24/2012 4:12:23 AM


Reply: