Cython compiled C extension: ImportError: dynamic module does not define init function

前端 未结 8 1443
盖世英雄少女心
盖世英雄少女心 2020-12-12 23:48

I have just compiled part of my C library as an extension using Cython, as a \"proof of concept\". I managed to hack the code (const correctnes problems etc aside), to final

8条回答
  •  死守一世寂寞
    2020-12-13 00:34

    Likewise a late answer... but I kept finding my way back to this question in particular. It probably is related to the mismatched names issue that Dologan addresses.

    What happened in my case was that I was adapting an example I'd gotten to work, and got the module does not define init function error. This was verified by using (e.g.)

    nm -m build/lib.macosx-10.9-x86_64-2.7/myproj.so

    In this command's output I searched for 'init' and found

    000000000000c0d0 (__TEXT,__text) external _initexample

    I had removed all instances of 'example' from my setup.py and .pyx file, but this persisted even after removing the extension from site-packages, removing the build and dist folders, etc. I finally found that the .cpp file being generated from my .pyx file was still referring to the class name in the example. Once I reran my setup.py, import works, and indeed the .so file includes

    000000000000c0a0 (__TEXT,__text) external _initmyproj

提交回复
热议问题