问题描述
我正在尝试编译一个需要 OpenFST 的 tensorflow 自定义操作 (http://www.openfst.org/twiki/bin/view/FST/WebHome).但是,我在运行时遇到了编译错误:
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')
并得到未定义符号错误未定义符号:_ZN3fst21ConvertToLegalCSymbolEPSs
,因此无法找到链接对象.
and get an undefined symbol error undefined symbol: _ZN3fst21ConvertToLegalCSymbolEPSs
, so it's not able to find the linked object.
这是我正在使用的 CMake 文件:
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)
包含外部库的 CMake 文件是否有任何明显的问题?没有太多编译 C++ 的经验.
Are there any obvious issues with the CMake file to include an external library? Don't have too much experience with compiling C++.
推荐答案
解决方案是重新编译 OpenFST:使 CFLAGS='-D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11' CXXFLAGS='-D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11'
因为 tensorflow 使用 D_GLIBCXX_USE_CXX11_ABI=0.
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.
这篇关于如何将 OpenFST 链接到 tensorflow 自定义操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!