1

I am using CFFI to call a C function with OpenMP from Python. My code works on one of my computers, but not the other with a very similar setup.

import os
from cffi import FFI

# test 
os.system("gcc -fopenmp -c test.c -o test.o")
os.system("gcc -o test.exe test.o -fopenmp")
os.system("test.exe")

# gateway
ffi = FFI()
os.system("gcc -o test.so test.c -shared -fopenmp")
ffi.cdef(r''' int main(); ''')        
lib = ffi.dlopen(r'''test.so''')
lib.main()

The error is

OSError: cannot load library test.so: error 0x45a

I am using Python 3.5 (the latest Anaconda distribution) and TDM-GCC 5.1.0. The test runs on both computers. What can explain the difference behavior?

1
  • Try running with LD_DEBUG=all. Commented Dec 5, 2016 at 13:29

1 Answer 1

1

Short version - you define your header (.h) and source files (.c) as usual with cffi. For openmp you have to include extra compile and linker arguments as follows:

import cffi

ffi = cffi.FFI()    
ffi.cdef(header_string)    
ffi.set_source(
    '_my_module_name',
    source_string,
    extra_compile_args=['-fopenmp'],
    extra_link_args=['-fopenmp'],
)
ffi.compile()
import _my_module_name
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.