【问题标题】:fatal error: google/protobuf/port_def.inc: No such file or directory #include <google/protobuf/port_def.inc>致命错误:google/protobuf/port_def.inc:没有这样的文件或目录#include <google/protobuf/port_def.inc>
【发布时间】:2019-11-14 06:05:57
【问题描述】:

我有窗户。我想使用库 tensorflow 创建一个 C++ 操作。从这个网站https://www.tensorflow.org/guide/extend/op#compile_the_op_using_your_system_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:\Python\Python37\lib\site-packages\tensorflow\include/tensorflow/core/framework/op_def_builder.h:24,
                 from C:\Python\Python37\lib\site-packages\tensorflow\include/tensorflow/core/framework/op.h:23,
                 from zero_out.cc:4:
C:\Python\Python37\lib\site-packages\tensorflow\include/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.

我不明白我该如何解决这个问题。如果您能帮我解决这个问题,我将不胜感激

【问题讨论】:

标签: c++ windows tensorflow g++ protobuf-c


【解决方案1】:

我认为您现在可能已经解决了这个问题,但是为了参考其他人发布一种可能的解决方案。找到 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

【讨论】:

    【解决方案2】:

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

    make clean
    make all -j 16
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-14
      • 2019-03-09
      • 2016-08-29
      • 2015-01-11
      • 2021-02-26
      • 1970-01-01
      • 2020-12-06
      相关资源
      最近更新 更多