title: Need help linking Tensorflow C++ API to C++ project
body: <p>I trained a model in Python using Tensorflow and exported it. My wish is to use the model from a c++ program for inference.</p>
  <p>I followed <a href="https://medium.com/vitrox-publication/deep-learning-frameworks-tensorflow-build-from-source-on-windows-python-c-cpu-gpu-d3aa4d0772d8" rel="nofollow noreferrer">this guide</a> and I successfully built some libraries using Bazel. The selected Tensorflow version is v4.2.0, without GPU.</p>
  <p>The following files were generated in the tensorflow directory:</p>
  <ul>
  <li>tensorflow.dll</li>
  <li>tensorflow.dll.runfiles_manifest</li>
  <li>tf_custom_op_library_additional_deps.dll.gen.def</li>
  <li>tensorflow.dll-2.params</li>
  <li>tensorflow.lib</li>
  <li>tf_custom_op_library_additional_deps.dll.gen.def-0.params</li>
  <li>tensorflow.pdb</li>
  <li>tensorflow.dll.if.exp</li>
  <li>tensorflow.dll.if.lib</li>
  <li>tensorflow_filtered_def_file.def</li>
  <li>includes</li>
  </ul>
  <p>In Visual Studio 2019 I added the includes directory for the compiler, and the tensorflow.dll.if.lib and tensorflow.lib  for the linker as inputs. I solved all compile errors and I don't get any linker error. I copied the tensorflow.dll to the directory of the source. The program does not complain about missing dll.</p>
  <p>When I run the folowing code:</p>
  <pre class="lang-cpp prettyprint-override"><code>#define NOMINMAX
  
  #include &quot;tensorflow/core/framework/graph.pb.h&quot;
  #include &quot;tensorflow/core/public/session.h&quot;
  #include &quot;tensorflow/core/public/version.h&quot;
  
  #include &lt;iostream&gt;
  
  int main() {
  
      std::cout &lt;&lt; tf_git_version() &lt;&lt; std::endl;
      std::unique_ptr&lt;tensorflow::Session&gt; session(tensorflow::NewSession({}));
      return 0;
  }
  </code></pre>
  <p>I obtain the following output:</p>
  <pre><code>unknown
  
  C:\...\x64\Debug\TensorflowTest.exe (process 10236) exited with code -1073741819.
  Press any key to close this window . . .
  </code></pre>
  <p>One can observe that the functions are not working as expected. The first one prints &quot;unknown&quot; instead of a version number, the second one crashes the application.</p>
  <p>After running in the debugger the line before the return statement, the following exception is thrown:</p>
  <pre><code>Exception thrown at 0x00007FFE6DF4B24B (tensorflow.dll) in TensorflowTest.exe: 0xC0000005: Access violation reading location 0x0000000000000018.
  </code></pre>
  <p>Call stack:</p>
  <pre><code>    tensorflow.dll!google::protobuf::Map&lt;int,class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &gt;::InnerMap::begin(void)   
      tensorflow.dll!google::protobuf::Map&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;,int&gt;::clear(void)  
      tensorflow.dll!google::protobuf::Map&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;,int&gt;::~Map&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;,int&gt;(void)  
      tensorflow.dll!tensorflow::ConfigProto::~ConfigProto(void)  
      TensorflowTest.exe!tensorflow::SessionOptions::~SessionOptions()
  </code></pre>
  <p>Please help me solve this problem.</p>