1

I am trying to use the c++ wrapper for tensorflow api from https://github.com/serizba/cppflow.

I have copied the git repository. Downloaded the tensorflow api files (copied them into the cppflow folder), when I build the project in the folder, and then tries to run it from the project file created I get 37 errors, all related to Model.obj and Tensor.obj.

LNK2019 unresolved external symbol __imp_TF_NewStatus referenced in function "public: __cdecl Model::Model(class std::basic_string,class std::allocator > const &)" (??0Model@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) example *\cppflow\examples\load_model\build\Model.obj 1

I am running it on Windows 10, with a c++ 17 compiler.

The CMakeFiles contain the following lines:

cmake_minimum_required(VERSION 3.10)
project(example)
set(CMAKE_CXX_STANDARD 17)
add_executable(example main.cpp ../../src/Model.cpp ../../src/Tensor.cpp)
target_include_directories(example PRIVATE ../../include)
target_link_libraries (example -ltensorflow)

I am trying to run a example from the github repo.

#include "../../include/Model.h"
#include "../../include/Tensor.h"
#include <numeric>
#include <iomanip>

int main() {
   Model model("../model.pb");
   model.init();

   auto input_a = new Tensor(model, "input_a");
   auto input_b = new Tensor(model, "input_b");
   auto output  = new Tensor(model, "result");

   std::vector<float> data(100);
   std::iota(data.begin(), data.end(), 0);

   input_a->set_data(data);
   input_b->set_data(data);

   model.run({input_a, input_b}, output);
   for (float f : output->get_data<float>()) {
       std::cout << f << " ";
   }
   std::cout << std::endl;

}

Does anybody have any suggestions?

Atle Kristiansen
  • 707
  • 7
  • 28
  • Does that mean I have placed the tensorflow c files in the wrong directory? – Atle Kristiansen Jun 24 '19 at 17:51
  • 1
    That means you missed something to setup the linking stage of your project correctly. You may elaborate about this aspect in your question, to get more concrete answers. – πάντα ῥεῖ Jun 24 '19 at 17:52
  • Well, the only thing I did was to download the tensorflow API, clone the git repo. Move the tensorflow API files into the cppflow folder (it was two folders a include and one lib). Created a folder named build within the examples\load_model, ran "cmake .." from within that folder, opened the project file which was created, and then tried to run the program from there. – Atle Kristiansen Jun 24 '19 at 17:58
  • I can see that the following link is in the CMakeLists "target_link_libraries (example -ltensorflow)" Does this mean that the Tensorflow folder should be within this folder? – Atle Kristiansen Jun 24 '19 at 18:05
  • _"Does this mean that the Tensorflow folder should be within this folder?"_ Nope, this would generate a different error that the library can't be found at all. Check if the generated library contains the missing symbols. – πάντα ῥεῖ Jun 24 '19 at 18:08
  • I get a warning that the include "target_link_libraries (example -ltensorflow)" is being ignored which may result in the error messages? option '/ltensorflow'; ignored example *\cppflow\examples\load_model\build\LINK 1 – Atle Kristiansen Jun 24 '19 at 18:10
  • Post a [mcve] as required here to get more concise answers. – πάντα ῥεῖ Jun 24 '19 at 18:12
  • I have posted every step I have done. Do you want the example given in the github repo? Because that is what I am trying to run – Atle Kristiansen Jun 24 '19 at 18:14
  • _"Do you want the example given in the github repo?"_ Questions need to be self contained here. External links don't count (other than decoration). – πάντα ῥεῖ Jun 24 '19 at 18:16
  • I have added the example code I am trying to run. Should I include the code from the includes as well? – Atle Kristiansen Jun 24 '19 at 18:22
  • "Downloaded the tensorflow api files (copied them into the cppflow folder), " – YScharf Apr 25 '22 at 10:01

1 Answers1

0

"Downloaded the tensorflow api files (copied them into the cppflow folder), " Try downloading tensorflow_c_api into separate folder. No need to place inside cppflow directory.

YScharf
  • 1,638
  • 15
  • 20