title: Calling C function from Python - undefined symbol error
body: <p>I am trying to call a C function from the Galil gclib from Python.  I am getting an undefined symbol OSError in Python so suspect a problem with my gcc command.  Especially since I don't understand all the arguments to gcc.</p>
  
  <p>This is my file gtest.c</p>
  
  <pre><code>#include "gclibo.h" //by including the open-source header, all other headers are pulled in.                                                              
  
  GReturn test()
  {
      GReturn rc;
      char buf[1024]; //traffic buffer                                                                                                                 
  
      GCon g; //var used to refer to a unique connection                                                                                               
  
      rc = GOpen("192.168.0.174 -d", &amp;g); //Open a connection to Galil, store the identifier in g.                                                     
      printf("rc: %d\n", (int) rc);
  
      rc = GInfo(g, buf, sizeof(buf));        
      printf("rc: %d\n", (int) rc);
      printf("info: %s\n", buf); //Print the connection info                                                                                           
  
      rc = GClose(g); //Don't forget to close!                                                                                                         
  
      return rc;
  }
  </code></pre>
  
  <p>I compiled it with:</p>
  
  <pre><code>gcc -shared -Wl,-soname,gtest -o gtest.so -fPIC gtest.c
  </code></pre>
  
  <p>In Python 2.7, I get:</p>
  
  <pre><code>In [1]: import ctypes
  In [2]: gtest = ctypes.CDLL('/home/mitch/wt1/gtest.so')
  ---------------------------------------------------------------------------
  OSError                                   Traceback (most recent call last)
  &lt;ipython-input-7-008ab6422af2&gt; in &lt;module&gt;()
  ----&gt; 1 gtest = ctypes.CDLL('/home/mitch/wt1/gtest.so')
  
  /usr/lib/python2.7/ctypes/__init__.pyc in __init__(self, name, mode, handle,     use_errno, use_last_error)
      363 
      364         if handle is None:
  --&gt; 365             self._handle = _dlopen(self._name, mode)
      366         else:
      367             self._handle = handle
  
  OSError: /home/mitch/wt1/gtest.so: undefined symbol: GInfo
  </code></pre>
  
  <p>Tried:</p>
  
  <pre><code>gcc -shared -Wl,-soname,gtest -o gtest.so -lgclib -lgclibo -fPIC gtest.c
  </code></pre>
  
  <p>which succeeds and then:</p>
  
  <pre><code>$ ldd gtest.so
  
    linux-vdso.so.1 =&gt;  (0x00007ffd076eb000)
    libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8284d7b000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f8285342000)
  </code></pre>