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

前端 未结 6 1233
生来不讨喜
生来不讨喜 2020-12-02 17:19

I tried to compile fizzbuzz.c, in order to import it by python. For building fizzbuzz.c,I used python setup.py build_ext -i.

A

6条回答
  •  日久生厌
    2020-12-02 17:43

    The error also occurs, when using boost::python, if the module name is different to the compiled .so file name. For example:

    hello.cpp

    #include 
    #include 
    using namespace std;
    using namespace boost::python;
    
    int helloWorld(){
        cout << "Hello world!" << endl;
        return 0;
    }
    
    BOOST_PYTHON_MODULE(libhello) {
        def("hello_world", helloWorld);
    }
    

    compilation command:

    g++ -fpic -shared -o libfoo.so -Wl,-soname,"libfoo.so" hello.cpp -I -L/usr/local/lib  -lboost_python-py34
    

    When including in python with import libfoo the following error occurs:

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

    This is because of "libhello" and "libfoo" do not match.

提交回复
热议问题