title: creating and using a dynamic shared library on solaris
body: <p>I am reading the procedure to create and use a dynamic shared library on solaris sparc server.
  below are the file i have :</p>
  
  <pre><code>&gt; ls -lrt
  total 8
  -rw-rw-r--   1 nobody   nobody       848 Nov 22 14:45 badmemlib.hh
  -rw-rw-r--   1 nobody   nobody      1924 Nov 22 14:46 badmemlib.cc
  -rw-rw-r--   1 nobody   nobody       330 Nov 22 14:49 my_prog.cc
  &gt; 
  </code></pre>
  
  <p>in the above files badmemlib.hh is the header file using which i am creating a shared library with the below command following what is mentioned in <a href="http://docs.oracle.com/cd/E18659_01/html/821-1383/bkamq.html" rel="nofollow">this</a> link.</p>
  
  <pre><code>&gt; CC -G -o libbad.so -h libbad.so -Kpic badmemlib.cc
  </code></pre>
  
  <p>after i run the above command i have these below files:</p>
  
  <pre><code>&gt; ls -lrt
  total 26
  -rw-rw-r--   1 nobody   nobody       848 Nov 22 14:45 badmemlib.hh
  -rw-rw-r--   1 nobody   nobody      1924 Nov 22 14:46 badmemlib.cc
  -rw-rw-r--   1 nobody   nobody       330 Nov 22 14:49 my_prog.cc
  -rwxrwxr-x   1 nobody   nobody      8284 Nov 22 15:11 libbad.so*
  &gt; 
  </code></pre>
  
  <p>as you can see libbad.so is built without any errors.
  Now my main is in the file my_prog.cc
  i am compiling the file my_prog.cc as below which following  <a href="http://docs.oracle.com/cd/E18659_01/html/821-1383/bkajr.html#bkajv" rel="nofollow">this</a>:
  and there were no errors.the binary  a.out is built.</p>
  
  <pre><code>&gt; CC -L. -lbad my_prog.cc
  &gt; ls -lrt
  total 184
  -rw-rw-r--   1 nobody   nobody       848 Nov 22 14:45 badmemlib.hh
  -rw-rw-r--   1 nobody   nobody      1924 Nov 22 14:46 badmemlib.cc
  -rw-rw-r--   1 nobody   nobody       330 Nov 22 14:49 my_prog.cc
  -rwxrwxr-x   1 nobody   nobody      8284 Nov 22 15:11 libbad.so*
  -rwxrwxr-x   1 nobody   nobody     80224 Nov 22 15:14 a.out*
  &gt; 
  </code></pre>
  
  <p>Now if i run a.out then the error i am facing is :</p>
  
  <pre><code>&gt; ./a.out
  ld.so.1: a.out: fatal: libbad.so: open failed: No such file or directory
  Killed
  </code></pre>
  
  <p>It mentions that library is not found but as you can see above the library is in the same directory!</p>
  
  <p>Could anybody pls help me!</p>
  
  <p>content of my_prog.cc.it actually generates a sigsegv and and the badmemlib files has a signal handler.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;string.h&gt;
  #include "badmemlib.hh"
  #ifdef SOLARIS /* needed with at least Solaris 8 */
  #include &lt;siginfo.h&gt;
  #endif
  
  int main(){ 
          char *where=(char *)0x123;
  
          printf( "About to write to %p\n", where);
          strcpy(where,"vijay");
  
          return(0);
  }
  </code></pre>