fatal error: nsync_cv.h: No such file or directory fatal error: nsync_cv.h: No such file or directory

fatal error: nsync_cv.h: No such file or directory

从TF1.3升级到TF1.4之后,自己写的op也要重新编译

TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
TF_LIB=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_lib())')

i=$1
o=${i/.cc/.so}

g++ -std=c++11 -shared $i -o $o -fPIC -I $TF_INC  -D_GLIBCXX_USE_CXX11_ABI=0 -L $TF_LIB

github上有人回答:
I was able to fix the issue by adding /usr/local/lib/python3.6/site-packages/tensorflow/include/external/nsync/public to my header search path (TF v1.4)
https://github.com/tensorflow/tensorflow/issues/12482

所以编译时增加一个include目录即可,具体如下:

TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
TF_LIB=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_lib())')

i=$1
o=${i/.cc/.so}

g++ -std=c++11 -shared $i -o $o -fPIC -I $TF_INC -I /usr/local/lib/python2.7/dist-packages/tensorflow/include/external/nsync/public/ -D_GLIBCXX_USE_CXX11_ABI=0 -L $TF_LIB

但是紧接着调用.so库是还会报错。
https://github.com/tensorflow/tensorflow/issues/13607

Then while trying to load the .so file I run into
tensorflow.python.framework.errors_impl.NotFoundError: ./max_align_bytes_op.so: undefined symbol: _ZTIN10tensorflow8OpKernelE

最终根据issue找到了更新版本的官方文档:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/extend/adding_an_op.md

TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
TF_LIB=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_lib())')

i=$1
o=${i/.cc/.so}


g++ -std=c++11 -shared $i -o $o  -fPIC -I$TF_INC -I$TF_INC/external/nsync/public -L$TF_LIB -ltensorflow_framework -O2  -D_GLIBCXX_USE_CXX11_ABI=0

猜你喜欢

转载自blog.csdn.net/tiankongtiankong01/article/details/80524277