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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章