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

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

我有 window 。我想使用库tensorflow创建一个C++ op。通过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.


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

最佳答案

我认为您现在可能已经解决了该问题,但仅供其他引用,以发布一种可能的解决方案。找到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

关于c++ - fatal error : google/protobuf/port_def. inc : No such file or directory #include <google/protobuf/port_def. inc>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56871990/

相关文章:

客户端未知的 MySQL 8.0 请求的身份验证方法(caching_sha2_password)

Windows 批处理脚本 - For/L 不起作用 - 简单

c++ - 将 32 0/1 值打包到单个 32 位变量的位中的最快方法是什么?

c++ - 模板模板参数 - 编译错误

c++ - 迭代两个 vector 迭代器比 boost_foreach 更快

tensorflow - tf.keras : Evaluating model. 使用 tf.data.Dataset 作为输入时更新中断

python - 添加带有偏移量的张量

c++ - 这个C++函数的时间复杂度是多少?

windows - 如何批量重命名子目录中特定文件类型的文件?

python - 如何顺序组合2个 tensorflow 模型?