MNN中Python接口pymnn源码编译

MNN中Python接口pymnn源码编译

第一步:protobuf源码编译

git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf/
./autogen.sh
./configure CFLAGS="-fPIC"  CXXFLAGS="-fPIC"
make
make check
sudo make install
sudo ldconfig

第二步:pymnn编译

cd mnn/
cd pymnn/pip_package

修改setup.py文件,否则会报如下错误:
(1)对’google::protobuf::Message::SerializeToOstream(std::ostream*) const’未定义的引用 collect2: error
(2)若出现site-packages/MNN-0.0.9-py3.7-linux-x86_64.egg/_tools.cpython-37m-x86_64-linux-gnu.so: undefined symbol:_ZNK6google8protobuf7Message18SerializeToOstreamEPSo错误
修改方式如下:

if IS_LINUX:
        tools_extra_link_args += ['-Wl,--whole-archive']
        tools_extra_link_args += tools_depend
        #tools_extra_link_args += ['-l:libprotobuf.a']
        tools_extra_link_args += ['-Wl,--no-whole-archive']
        tools_extra_link_args += ['-lz']

修改为:

if IS_LINUX:
        tools_extra_link_args += ['-Wl,--whole-archive']
        tools_extra_link_args += tools_depend
        tools_extra_link_args += ['/usr/local/lib/libprotobuf.a']
        tools_extra_link_args += ['-Wl,--no-whole-archive']
        tools_extra_link_args += ['-lz']
python build_deps.py
python setup.py install

你可能感兴趣的:(MNN)