8

I have windows. And I want to create an C++ op using library tensorflow. From this site https://www.tensorflow.org/guide/extend/op#compile_the_op_using_your_system_compiler_tensorflow_binary_installation I understood that I should do folowing:

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

I did that. But I got next problem:

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.

I don't understand how can I solve this problem. I would be really grateful if you can help me to solve this problem

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
NN_05
  • 179
  • 1
  • 1
  • 8
  • Hi, try to build and install your own protobuf https://github.com/protocolbuffers/protobuf/blob/master/cmake/README.md (accurately choose src version) – rinatdobr Dec 20 '19 at 10:36

2 Answers2

4

I think you might have solved the problem by now, but for the reference of others posting one possible solution. Find the tensorflow include directory path and include it while compiling your code. You can manually check that the header file (missing in your case) is present in the include path.

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

and modify your compile command to include the tf_include_dir i.e.

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

I use a simple way, whenever make fails:

make clean
make all -j 16
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Harsh
  • 77
  • 2
  • 8
  • This is not a solution to the problem. There is no sign of Make in the question either. – Vala Aug 30 '23 at 19:39