How to link OpenFST to tensorflow custom op?

假装没事ソ 提交于 2019-12-13 00:49:34

问题


I'm trying to compile a tensorflow custom op that requires OpenFST (http://www.openfst.org/twiki/bin/view/FST/WebHome). However, I'm running into compilation errors where I run:

import tensorflow as tf
decoder_op = tf.load_op_library('./libfst_decoder.so')

and get an undefined symbol error undefined symbol: _ZN3fst21ConvertToLegalCSymbolEPSs, so it's not able to find the linked object.

This is the CMake file I'm using:

cmake_minimum_required(VERSION 3.5)

execute_process(COMMAND python3 -c "import tensorflow; print(tensorflow.sysconfig.get_include())" OUTPUT_VARIABLE Tensorflow_INCLUDE_DIRS)

set (CMAKE_CXX_FLAGS "--std=c++11 -fPIC -O2 -D_GLIBCXX_USE_CXX11_ABI=0")

link_directories("/miniconda/envs/py36/lib/python3.6/site-packages/tensorflow")
include_directories(${Tensorflow_INCLUDE_DIRS})
include_directories("/usr/local/include")
add_library(fst_decoder SHARED fst_decoder.cc simple_decoder.cc)
target_link_libraries(fst_decoder -ltensorflow_framework -lfst -ldl -lm)

Are there any obvious issues with the CMake file to include an external library? Don't have too much experience with compiling C++.


回答1:


Solution is to recompile OpenFST with: make CFLAGS='-D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11' CXXFLAGS='-D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11' as tensorflow uses D_GLIBCXX_USE_CXX11_ABI=0.



来源:https://stackoverflow.com/questions/56352297/how-to-link-openfst-to-tensorflow-custom-op

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!