Rob Rob - 1 year ago 216
Python Question

Python Extension with openmp in OS X

I have created a python extension that works correctly in Linux but doesn't work in os x.

The C code makes use of the openmp library.

The C compiler that is preinstalled in os x is clang and the preinstalled python has been built with clang. That clang doesn't support openmp.

I can compile and run my code by installing gcc-6 by:

brew install gcc

I can build my libary by including in the file the environment variable CC:


And I include the gcc library path in the setup configuration:

library_dirs = ["/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/","../build/"],

But then I obtain errors when I load my library from python:

import myLibraryName

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/, 2): Symbol not found: ___emutls_get_address
Referenced from: /usr/local/opt/gcc/lib/gcc/6/libgomp.1.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /usr/local/opt/gcc/lib/gcc/6/libgomp.1.dylib

What should I do? What is the correct procedure create a python extension in OS X that makes use of the openmp library?

Rob Rob
Answer Source

I thik I have solved this issue. This is the project I am working on:

In resume:

1 - I installed gcc6 by

brew install gcc

2 - Then I declared the path to gcc in a environment variables in the file


3 - I left the CFLAGS environment variable empty:


4 - In the extension module I included the file libgomp.a associated to gcc6 and I used the extra ling arg "static":

ext_modules = [ 
        sources = ['myexample.c'],
        extra_objects = ["/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/libgomp.a",
            ....Object files of my library
        library_dirs = ["../build/"],

setup( name = 'LIBNAME', version = '1.0', description="My extension description", install_requires=[ 'numpy', 'scipy', ], url='', ext_modules = ext_modules )

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download