2

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:

File "foo.py", line 2, in <module>
    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

And I use these cmds:

gcc -fPIC -std=c99 -lm -Wall -fopenmp -pedantic -c foo.c
gcc -shared -o libfoo.so foo.o
python foo.py

I already googled and found a ''solution'' online, but I don't understand what is meant with:

I suppose I should set restype on constructors to ctypes.c_void_p.
And that I should set the corresponding types in argtypes on called
functions to ctypes.c_void_p. Will this cause necessary conversions
to take place? I'd like some confirmation that this is the right way
to approach this situation.

What does the solution mean or do you know an other way?

[update]

So here is the correct cmd line options with the help from Iulian Şerbănoiu:

gcc -fPIC -std=c99 -lm -Wall -fopenmp -pedantic -c foo.c
gcc -shared -lgomp -lrt  -o libfoo.so foo.o
python foo.py
2
  • 1
    This is where I ask the dumb question of "Why aren't you linking against OpenMP?". Commented Jun 24, 2010 at 16:31
  • I thought -fopenmp links against OpenMP or did I understand something wrong? Commented Jun 24, 2010 at 16:33

2 Answers 2

3

Try adding -lgomp option in order to link with openmp library. From here.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to include the -fopenmp flag also when linking:

gcc -shared -fopenmp -o libfoo.so foo.o

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.