cjweeks / tensorflow-cmake

Integrate TensorFlow with CMake projects effortlessly
MIT License
331 stars 83 forks source link

undefined reference to ClientSession constructor and destructor #27

Closed ASchtt closed 6 years ago

ASchtt commented 6 years ago

Hello there, first thanks for providing this nice add on for tensorflow:) However I am unable to build the code sippet from the tensorflow c++ API introduction with it...Here is my codesnippet:

#include "tensorflow/core/public/session.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/cc/client/client_session.h"
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/tensor.h" 

int main(int argc, char** argv )
{
namespace tf = tensorflow;
tf::Scope root = tf::Scope::NewRootScope();
// Matrix A = [3 2; -1 0]
auto A = tf::ops::Const(root, { {3.f, 2.f}, {-1.f, 0.f}});
// Vector b = [3 5]
auto b = tf::ops::Const(root, { {3.f, 5.f}});
// v = Ab^T
auto v = tf::ops::MatMul(root.WithOpName("v"), A, b, tf::ops::MatMul::TransposeB(true));
std::vector<tf::Tensor> outputs;
tf::ClientSession session(root);
// Run and fetch v
//TF_CHECK_OK(session.Run({v}, &outputs));
session.Run({v}, &outputs);
// Expect outputs[0] == [19; -3]
LOG(INFO) << outputs[0].matrix<float>();
return 0;
}

And the error messages I get at compiling: undefined reference to tensorflow::ClientSession::ClientSession(tensorflow::Scope const&) undefined reference to tensorflow::ClientSession::Run(std::vector<tensorflow::Output, std::allocator<tensorflow::Output> > const&, std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> >*) const' undefined reference to tensorflow::ClientSession::~ClientSession()' undefined reference to tensorflow::ClientSession::~ClientSession()'

Is it possible that this has something to do with the cmake-inclusion or do you think its a problem with my tensorflow installation? I only have this problem with the ClientSession, if a run a "normal" Session I don't get any errors...

cjweeks commented 6 years ago

Hello, this was actually an issue with this repository; I had neglected to include some dependencies in the added build rule. I have updated the README with a revised rule, and your code now works using the latest version of TensorFlow. Please let me know if this works for you.

ASchtt commented 6 years ago

Yep, perfect, that fixed the issue and now it works like a charm:) Thanks a lot!

developer-mayuan commented 6 years ago

@cjweeks I'm currently using your repository on Tensorflow r1.1 version and this issue still exists.