title: Using a static variable of a shared library in more than one functions of a same exe, but different object file
body: <p>(i have edited my original question to make it more understandable)</p>
  
  <p>here is the prototype for the problem ....</p>
  
  <p>//Txn.h ---this has a static variable,  usable by the pgms including it.</p>
  
  <pre><code>class Txn
  {
  public:
  static int i;
  static void incr_int();
  };
  Txn::i=0;
  </code></pre>
  
  <p>//Txn.cpp</p>
  
  <pre><code>void Txn::incr_int() {i++;}
  </code></pre>
  
  <p>->produce LibTxn.so<br>
  //class1.cpp  -> one of the pgm using the static var from Txn.h</p>
  
  <pre><code>#include Txn.h
  Txn::incr_int()
  </code></pre>
  
  <p>-> produce class1.o, with LibTxn.so.<br>
  // class2.cpp ->another pgm using the static var from Txn.h</p>
  
  <pre><code>#include Txn.h
  cout&lt;&lt;"Txn::i;
  </code></pre>
  
  <p>-> produce class2.o, by including LibTxn.so<br>
  -> .produce class3 (an exe) by using class1.o,class2.o. Since, both class1 and 2 has the statement "Txn::i=0" from "Txn.h", multiple declaration issue happens.<br>
  -> .If I remove the statement "Txn::i=0" from Txn.h, then "undefined reference" error appears.<br>
  -> .At high lvl, this problem is a kind of having a session variable, which should be assessible from any func in a exe. Those func can be in any obj files used to form the exe. I am fine for any sol, even without static. But I can't change the creation of different .o files (which are using this session var) and combining the .o to produce the exe.</p>