2

I have a library that I compiled with gcc using -fopenmp and linking to libmkl_gnu_thread.a.

When I try to load this library using ctypes I get the error message undefined symbol: GOMP_critical_end

Compiling this without openmp and linking to libmkl_sequential.a instead of gnu_thread, the library works fine, but I'd rather not have to build different versions in order to support Python.

How do I fix this error? Do I need to build python from source with openmp support? I'd like to avoid this since users don't want to have to build their own python to use this software.

I'm using python2.7.6.

5
  • When you build your library are you linking to -lgomp? Commented Sep 11, 2014 at 20:24
  • As far as I can tell, no. Should I be? Commented Sep 11, 2014 at 20:47
  • Yes, that should fix the problem Commented Sep 11, 2014 at 21:01
  • If you are using GCC to link the library, add -fopenmp. If you are using ld instead, add -lgomp. Commented Sep 12, 2014 at 8:26
  • I'll accept Hristo Iliev's answer if you make it an answer. Commented Sep 13, 2014 at 1:03

1 Answer 1

4

Having -fopenmp while compiling enables OpenMP support and introduces in the resultant object file references to functions from the GNU OpenMP run-time support library libgomp. You should then link your shared object (a.k.a. shared library) against libgomp in order to tell the run-time linker to also load libgomp (if not already loaded via some other dependency) whenever your library is used so that it could resolve all symbols.

Linking against libgomp can be done in two ways:

  • If you use GCC to also link the object files and produce the shared object, just give it the -fopenmp flag.
  • If you use the system linker (usually that's ld), then give it the -lgomp option.

A word of warning for the second case: if you are using GCC that is not the default system-wide one, e.g. you have multiple GCC versions installed or use a version that comes from a separate package or have built one yourself, you should provide the correct path to libgomp.so that matches the version of GCC.

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

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.