[hypermail] link a program with two libraries that use same global variable

From: AMMAR,LAMIA (HP-USA,ex1) <"AMMAR,LAMIA_at_hypermail-project.org>
Date: Fri, 8 Nov 2002 10:58:28 -0500
Message-ID: <2F1E6AB90ECAD311943700A0C9E3B154070820DE_at_xatl03.atl.hp.com>


Suppose you have two libraries and both libraries include a declaration of a global variable "abc". You need to link both libraries into your executable. One is available only as a shared library, libO.sl. The other is available as either libN.a or libN.sl, your choice.

Assume that the declarations for abc in the two libraries are incompatible -- maybe one is an int, and the other is *char. When you link these two libraries with your program, I believe that by default all the references to abc from both libraries will resolve to one instance of abc, either the int or the *char. This won't work well :-).

Which instance of abc is used, and what happens when you run the program depends on (at least) the order the libraries are searched, whether libN is an archive or shared library, and how the references to abc happen to occur.

Let me know if there is a workaround for this. Thanks
Lamia



Lamia Mansour Ammar
Sr. Technical Consultant
Software Services
HP Consulting
404.774.4022 Received on Fri 08 Nov 2002 08:51:07 PM GMT

This archive was generated by hypermail 2.2.0 : Thu 22 Feb 2007 07:33:54 PM GMT GMT