致命错误:google/protobuf/port_def.inc:没有这样的文件或目录 #include < google/protobuf/port_def.inc>

fatal error: google/protobuf/port_def.inc: No such file or directory #include <google/protobuf/port_def.inc>

本文关键字:inc def port google protobuf #include lt gt 致命错误 文件      更新时间:2023-10-16

我有Windows。我想使用库TensorFlow创建C OP。在此站点https://www.tensorflow.org/guide/extend/op#compile_the_op_uside_your_your_system_compiler_compiler_tensorflow_binary_installation我知道我应该做:

TF_CFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') )
TF_LFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))') )
g++ -std=c++11 -shared zero_out.cc -o zero_out.so -fPIC ${TF_CFLAGS[@]} ${TF_LFLAGS[@]} -O2

我做到了。但是我得到了下一个问题:

In file included from C:PythonPython37libsite-packagestensorflowinclude/tensorflow/core/framework/op_def_builder.h:24,
                 from C:PythonPython37libsite-packagestensorflowinclude/tensorflow/core/framework/op.h:23,
                 from zero_out.cc:4:
C:PythonPython37libsite-packagestensorflowinclude/tensorflow/core/framework/op_def.pb.h:10:10: fatal error: google/protobuf/port_def.inc: No such file or directory
 #include google/protobuf/port_def.inc
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

我不明白如何解决这个问题。如果您能帮助我解决此问题

,我将非常感谢

我认为您现在可能已经解决了问题,但要引用其他提出一个可能的解决方案的引用。查找TensorFlow包含目录路径,并在编译代码时包含它。您可以手动检查标题文件(案例中缺少(是否存在于包含路径中。

tf_include_dir=($(python -c "import tensorflow as tf; print(tf.sysconfig.get_include())"))

并修改您的编译命令以包括tf_include_dir,即

g++ -std=c++11 -Itf_include_dir -shared zero_out.cc -o zero_out.so -fPIC ${TF_CFLAGS[@]} ${TF_LFLAGS[@]} -O2

我使用一种简单的方法,每当make失败时:

make clean
make all -j 16