cjweeks / tensorflow-cmake

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

Linking errors linking CXX executable ../bin/external-project #42

Closed jreuben11 closed 6 years ago

jreuben11 commented 6 years ago

on MacOS, I get

Undefined symbols for architecture x86_64:
  "tensorflow::NewSession(tensorflow::SessionOptions const&, tensorflow::Session**)", referenced from:
      _main in main.cc.o
  "tensorflow::ConfigProto::~ConfigProto()", referenced from:
      tensorflow::SessionOptions::~SessionOptions() in main.cc.o
  "tensorflow::SessionOptions::SessionOptions()", referenced from:
      _main in main.cc.o
  "tensorflow::internal::LogMessageFatal::LogMessageFatal(char const*, int)", referenced from:
      tensorflow::core::RefCounted::~RefCounted() in main.cc.o
  "tensorflow::internal::LogMessageFatal::~LogMessageFatal()", referenced from:
      tensorflow::core::RefCounted::~RefCounted() in main.cc.o
  "tensorflow::internal::CheckOpMessageBuilder::ForVar2()", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* tensorflow::internal::MakeCheckOpString<int, int>(int const&, int const&, char const*) in main.cc.o
  "tensorflow::internal::CheckOpMessageBuilder::NewString()", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* tensorflow::internal::MakeCheckOpString<int, int>(int const&, int const&, char const*) in main.cc.o
  "tensorflow::internal::CheckOpMessageBuilder::CheckOpMessageBuilder(char const*)", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* tensorflow::internal::MakeCheckOpString<int, int>(int const&, int const&, char const*) in main.cc.o
  "tensorflow::internal::CheckOpMessageBuilder::~CheckOpMessageBuilder()", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* tensorflow::internal::MakeCheckOpString<int, int>(int const&, int const&, char const*) in main.cc.o
  "tensorflow::Status::ToString() const", referenced from:
      checkStatus(tensorflow::Status const&) in main.cc.o
ld: symbol(s) not found for architecture x86_64
jreuben11 commented 6 years ago

solution:

cc_binary(
    name = "libtensorflow_all.so",
    linkshared = 1,
    linkopts = ["-Wl,-all_load",
                "-Wl,-exported_symbols_list",  # This line must be directly followed by the exported_symbols.lds file
                "$(location //tensorflow:tf_exported_symbols.lds)",
    ],
    deps = [
        "//tensorflow:tf_exported_symbols.lds",
        "//tensorflow:tf_version_script.lds",
        "//tensorflow/core:core_cpu_impl",
        "//tensorflow/core:framework_internal_impl",
        "//tensorflow/core:gpu_runtime_impl",
        "//tensorflow/core/grappler/optimizers:custom_graph_optimizer_registry_impl",
        "//tensorflow/core:lib_internal_impl",
        "//tensorflow/stream_executor:stream_executor_impl",
        "//tensorflow:tf_framework_version_script.lds",

        "//tensorflow/c/eager:c_api",
        "//tensorflow/cc/profiler",
        "//tensorflow/core:framework_internal",
        "//tensorflow/core:tensorflow",
        "//tensorflow/cc:cc_ops",
        "//tensorflow/cc:client_session",
        "//tensorflow/cc:scope",
        "//tensorflow/c:c_api",
    ],
)