2015-11-10 52 views
1

我想通過使用Cython在Python中使用一些C函數。在這裏,我注意到,如果我用GCC-5編譯C代碼(爲了使用的Cilk)nm列出了導致*。所以,功能少了很多入口:ImportError:Cython和gcc-5

0000000000201030 B __bss_start 
0000000000201030 b completed.6973 
       w [email protected]@GLIBC_2.2.5 
00000000000005c0 t deregister_tm_clones 
0000000000000630 t __do_global_dtors_aux 
0000000000200df8 t __do_global_dtors_aux_fini_array_entry 
0000000000201028 d __dso_handle 
0000000000200e08 d _DYNAMIC 
0000000000201030 D _edata 
0000000000201038 B _end 
00000000000006a8 T _fini 
0000000000000670 t frame_dummy 
0000000000200df0 t __frame_dummy_init_array_entry 
00000000000006b8 r __FRAME_END__ 
0000000000201000 d _GLOBAL_OFFSET_TABLE_ 
       w __gmon_start__ 
0000000000201031 B __gnu_lto_slim 
0000000000201032 B __gnu_lto_v1 
0000000000000570 T _init 
       w _ITM_deregisterTMCloneTable 
       w _ITM_registerTMCloneTable 
0000000000200e00 d __JCR_END__ 
0000000000200e00 d __JCR_LIST__ 
       w _Jv_RegisterClasses 
00000000000005f0 t register_tm_clones 
0000000000201030 d __TMC_END__ 

和我所有的自我寫功能丟失。此外,我收到錯誤

ImportError: dynamic module does not define init function (initcython_wrapper) 

我該如何解決這個問題,爲什麼?

pyx -file的內容:

from libcpp cimport bool as bool_t 
cdef extern from "complex.h": 
    pass 

cimport numpy as np 

# if you want to use the Numpy-C-API from Cython 
# (not strictly necessary for this example, but good practice) 
np.import_array() 

# cdefine the signature of our c function 
cdef extern from "GNLSE_RHS.h": 
    void compute(int size, double *a, double *b) 
    void speedcompute(int size, double *a, double *b) 
    void test_fft(int size, double complex *a, double complex *b) 

# create the wrapper code, with numpy type annotations 
def compute_func(np.ndarray[double, ndim=1, mode="c"] in_array not None, 
        np.ndarray[double, ndim=1, mode="c"] out_array not None): 
    compute(in_array.shape[0], <double*> np.PyArray_DATA(in_array), 
       <double*> np.PyArray_DATA(out_array)) 

def speedcompute_func(np.ndarray[double, ndim=1, mode="c"] in_array not None, 
        np.ndarray[double, ndim=1, mode="c"] out_array not None): 
    speedcompute(in_array.shape[0], <double*> np.PyArray_DATA(in_array), 
       <double*> np.PyArray_DATA(out_array)) 

def fft_func(np.ndarray[complex, ndim=1, mode="c"] in_array not None, 
       np.ndarray[complex, ndim=1, mode="c"] out_array not None): 
    test_fft(in_array.shape[0], <complex*> np.PyArray_DATA(in_array), 
      <complex*> np.PyArray_DATA(out_array)) 

,並在setup.py文件的命令行選項:

os.environ["CC"] = "gcc-5" 
os.environ["CXX"] = "g++-5" 
# The configuration object that hold information on all the files 
# to be built. 
config = Configuration('', parent_package, top_path) 
config.add_extension(name='cython_wrapper', 
        sources=['cython_wrapper.pyx', 'GNLSE_RHS.c'], 
        # libraries=['m'], 
        include_dirs=[numpy.get_include(), "/opt/intel/compilers_and_libraries_2016.0.109/linux/mkl/include"], 
        #libraries=["m", "pthread", "gsl", "gslcblas"], 
        depends=['GNLSE_RHS.c'], 
        extra_compile_args=["-DMKL_ILP64 -mavx -msse4.2 -msse3 -msse2 -m64 -Ofast -flto -march=native -funroll-loops -std=gnu99"], 
        extra_link_args=["-Wl,--start-group /opt/intel/compilers_and_libraries_2016.0.109/linux/mkl/lib/intel64/libmkl_intel_ilp64.a /opt/intel/compilers_and_libraries_2016.0.109/linux/mkl/lib/intel64/libmkl_core.a /opt/intel/compilers_and_libraries_2016.0.109/linux/mkl/lib/intel64/libmkl_sequential.a -Wl,--end-group -lpthread -lm -ldl -lfftw3 -lfftw3_threads"]) 

回答

1

我能解決我的問題:背後的原因是不編譯器,但選項-fltogcc-5一起使用時會生成奇怪的代碼。刪除此選項生成可用的代碼。