linking (mixing shared libs and static archives)

linking (mixing shared libs and static archives)

Post by Trond Norby » Tue, 11 Aug 1998 04:00:00



can I mix shared libs and static archives when I link a program, or
must all the symbols in the shared objects be defined in shared objects.

I am currently splitting up a huge static archive into smaller shared
objects, and when I try to link the program, I have placed the static
archive at the end to 'define all undefined symbols'. When I did this
someone tried to execute one of the linked files, but it dumped core
before it reached main. When I inserterted -Bstatic and linked the
whole application static, everything worked fine. Could someone
please tell me if I can have unresolved symbols in a shared lib that
will be filled in by the static archive.

Trond Norbye

 
 
 

linking (mixing shared libs and static archives)

Post by Mike Walke » Thu, 13 Aug 1998 04:00:00



> can I mix shared libs and static archives when I link a program, or
> must all the symbols in the shared objects be defined in shared objects.

mixing is fine.  References which bind to shared objects will bind to
those
shared objects at run-time.  References which bind to the archive will
be
actracted from the archive at link-edit time and placed in the
executable.

Should work fine.  You can audit which modules are extracted from
the archive with the link-editor debugging option

        LD_OPTIONS="-Dfiles" cc <regular link line>

Quote:

> I am currently splitting up a huge static archive into smaller shared
> objects, and when I try to link the program, I have placed the static
> archive at the end to 'define all undefined symbols'. When I did this
> someone tried to execute one of the linked files, but it dumped core
> before it reached main. When I inserterted -Bstatic and linked the
> whole application static, everything worked fine. Could someone
> please tell me if I can have unresolved symbols in a shared lib that
> will be filled in by the static archive.

The answer is yes - this should work fine.

--
---

Linker Developer
SunSoft Inc.
2500 Garcia Ave, M/S UMPK17-307 Mountain View, CA 94043

 
 
 

linking (mixing shared libs and static archives)

Post by Trond Norby » Thu, 13 Aug 1998 04:00:00


Thank you for clearing that out. I had some problems running the code at
once (one process died and the stack-trace told me that the process had
not reached main yet....), so I wanted to be sure that it _should_ work.

I also have another question about linking. If I have a shared lib
called liba.so with a global variable. I then create a new shared lib
called libb.so and I prelink this lib with liba.so.
If I now create a program and link it with both liba and libb, will the
global symbol be defined twice when the program is loaded into memory,
or will the runtime linker know that the lib has been loaded already. I
have spoked with a guy that have testet this under windoze NT, and he
said that it  was a problem there.

Trond Norbye



> > can I mix shared libs and static archives when I link a program, or
> > must all the symbols in the shared objects be defined in shared objects.

> mixing is fine.  References which bind to shared objects will bind to
> those
> shared objects at run-time.  References which bind to the archive will
> be
> actracted from the archive at link-edit time and placed in the
> executable.

> Should work fine.  You can audit which modules are extracted from
> the archive with the link-editor debugging option

>         LD_OPTIONS="-Dfiles" cc <regular link line>

 
 
 

linking (mixing shared libs and static archives)

Post by Casper H.S. Dik - Network Security Engine » Sat, 15 Aug 1998 04:00:00


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>I also have another question about linking. If I have a shared lib
>called liba.so with a global variable. I then create a new shared lib
>called libb.so and I prelink this lib with liba.so.
>If I now create a program and link it with both liba and libb, will the
>global symbol be defined twice when the program is loaded into memory,
>or will the runtime linker know that the lib has been loaded already. I
>have spoked with a guy that have testet this under windoze NT, and he
>said that it  was a problem there.

There's no problem on Solaris as long as the dynamic linker finds it
by the same name.  It will just think "been there, done that" and skip
all further occurences.

It's actuall very common on Solaris: e.g., libsocket is linked with
-lnsl and -lc; -lnsl is linked w/ -lc, -lmp and -ldl, libc is linked w/ -ldl.

So if you link -lsocket -lnsl -lc (very common, though -lc is added by the
compiler), you really get -lsocket, -lnsl, -lc, -lmp, -ldl.  But you
only get one each.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

1. linking static archive to another static archive

Hi,

Is linking a static library to another static library possible?

I have a static library, bar.a.  I have another library foo.a that uses
some of the functions in bar.a

Could someone show me how I can link foo.a to bar.a?

On Solaris, I get "embedded archive not possible".  I think under AIX,
linking an archive to another archive is possible.  Is this a
platform-dependent behavior?

In the FAQ, it talks about exploding both static archives into another
directory and then recombining them.  Is this the problem I'm
encountering?  What if I'm unable to do this?

Thanks for any help,

K.

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Removing solaris daemons ?

3. C++ linking problem creating a static lib from another static lib.

4. 1024x768-resolution on TVGA8900c

5. Linking serveral archive libs into shared object

6. Posix vs BSD line discipline

7. link both with static and shared lib

8. Modem hangs.

9. Static objects linked to shared lib.

10. static linking of objects from shared lib!

11. Linking with shared and static libs

12. static lib works fine, but why not the shared lib version

13. convert shared lib to archive lib ?