title: Linking using OpenMp with ctypes
body: <p>I have a c99 function that uses openmp, which works as expected. I also wrote a python interface using ctypes which causes the problem. Ctypes/python can not find the library for openmp. Here is the error message:</p>
  
  <pre><code>File "foo.py", line 2, in &lt;module&gt;
      foobar=cdll.LoadLibrary("./libfoo.so")
    File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in LoadLibrary
      return self._dlltype(name)
    File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
      self._handle = _dlopen(self._name, mode)
  OSError: ./libfoo.so: undefined symbol: GOMP_parallel_end
  </code></pre>
  
  <p>And I use these cmds:</p>
  
  <pre><code>gcc -fPIC -std=c99 -lm -Wall -fopenmp -pedantic -c foo.c
  gcc -shared -o libfoo.so foo.o
  python foo.py
  </code></pre>
  
  <p>I already googled and found a ''solution'' <a href="http://blog.gmane.org/gmane.comp.python.ctypes/month=20071001Blockquote" rel="nofollow noreferrer">online</a>, but I don't understand what is meant with:</p>
  
  <p><Blockquote>
  I suppose I should set restype on constructors to ctypes.c_void_p.<br>
  And that I should set the corresponding  types in argtypes on called<br>
  functions to ctypes.c_void_p.  Will this cause necessary conversions<br>
  to take place? I'd like some confirmation that this is the right way<br>
  to approach this situation.
  </Blockquote> </p>
  
  <p>What does the solution mean or do you know an other way?</p>
  
  <p><strong>[update]</strong></p>
  
  <p>So here is the correct cmd line options with the help from Iulian Şerbănoiu:</p>
  
  <pre><code>gcc -fPIC -std=c99 -lm -Wall -fopenmp -pedantic -c foo.c
  gcc -shared -lgomp -lrt  -o libfoo.so foo.o
  python foo.py
  </code></pre>