Tensorflow 未定义引用 'tensorflow::Scope::NewRootScope()'

Tensorflow undefined reference to 'tensorflow::Scope::NewRootScope()'

本文关键字:NewRootScope Scope 未定义 Tensorflow tensorflow 引用      更新时间:2023-10-16

我已经对多个体系结构进行了tensorflow构建的交叉编译,并且使用cmake(通过cmakelists.txt)触发了Android中的编译。在CMAKE文件中,我添加了以下内容:

# Link our new shared lib to its dependencies
set(libs_DIR $ENV{HOME}/tensorflow_gens/${ANDROID_ABI})
target_link_libraries(
    tensorflow
  ${libs_DIR}/libandroid_tensorflow_kernels.lo
  ${libs_DIR}/libandroid_tensorflow_lib_lite.lo
  ${libs_DIR}/libandroid_tensorflow_lib.lo
  ${libs_DIR}/libtensorflow-core.a
  ${libs_DIR}/libprotobuf.a
  ${libs_DIR}/libprotobuf_lite.a
  ${libs_DIR}/libprotos_all_cc_impl.a
  ${libs_DIR}/libnsync.a
  ${libs_DIR}/nsync.a
  android
  log
  m
  z
)

但我最终得到了一堆未找到错误消息,例如以下内容:

Execution failed for task ':tensorflow:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process 
/Users/xxxx/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/.externalNativeBuild/cmake/debug/armeabi --target tensorflow}
      [1/2] Building CXX object CMakeFiles/tensorflow.dir/src/main/cpp/tensorflow-lib.cpp.o
      [2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi/libtensorflow.so
      FAILED: : && /Users/xxxx/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  
        --target=armv5te-none-linux-androideabi 
        --gcc-toolchain=/Users/xxxx/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 
        --sysroot=/Users/xxxx/Library/Android/sdk/ndk-bundle/sysroot -fPIC 
        -isystem /Users/Sujit/xxxx/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi 
        -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong 
        -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack 
        -Wformat -Werror=format-security -frtti -fexceptions -std=c++11 -fpic -DTF_LEAN_BINARY -DGOOGLE_PROTOBUF_NO_RTTI 
        -DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER -O0 -fno-limit-debug-info  
        -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot 
      /Users/xxxx/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm 
         -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined 
         -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now
         -Wl,--allow-multiple-definition                               
         -Wl,--whole-archive -shared -Wl,-soname,libtensorflow.so -o 
         ../../../../build/intermediates/cmake/debug/obj/armeabi/libtensorflow.so 
      CMakeFiles/tensorflow.dir/src/main/cpp/tensorflow-lib.cpp.o 
         /Users/xxxx/work/tensorflow_gens/armeabi/libandroid_tensorflow_kernels.lo 
         /Users/xxxx/work/tensorflow_gens/armeabi/libandroid_tensorflow_lib_lite.lo 
         /Users/xxxx/work/tensorflow_gens/armeabi/libandroid_tensorflow_lib.lo 
         /Users/xxxx/work/tensorflow_gens/armeabi/libtensorflow-core.a 
         /Users/xxxx/work/tensorflow_gens/armeabi/libprotobuf.a 
         /Users/xxxx/work/tensorflow_gens/armeabi/libprotobuf_lite.a 
         /Users/xxxx/work/tensorflow_gens/armeabi/libprotos_all_cc_impl.a 
         /Users/xxxx/work/tensorflow_gens/armeabi/libnsync.a /Users/xxxx/work/tensorflow_gens/armeabi/nsync.a -landroid -llog -lm -lz -latomic -lm "/Users/Sujit/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/libgnustl_static.a" && :
      /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:39: error: undefined reference to 'tensorflow::Scope::NewRootScope()'
      /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:40: error: undefined reference to 'tensorflow::ClientSession::ClientSession(tensorflow::Scope const&)'
      /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:42: error: undefined reference to 'tensorflow::ops::Sqrt::Sqrt(tensorflow::Scope const&, tensorflow::Input)'
      /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:44: error: undefined reference to 'tensorflow::ClientSession::Run(std::vector<tensorflow::Output, std::allocator<tensorflow::Output> > const&, std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> >*) const'
      /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:47: error: undefined reference to 'tensorflow::ClientSession::~ClientSession()'
      /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:47: error: undefined reference to 'tensorflow::Scope::~Scope()'
      /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:47: error: undefined reference to 'tensorflow::ClientSession::~ClientSession()'
      /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:47: error: undefined reference to 'tensorflow::Scope::~Scope()'
      /Users/xxxx/work/tensorflow_gens/includes/tensorflow/cc/framework/ops.h:245: error: undefined reference to 'tensorflow::Operation::Operation(tensorflow::Node*)'
      clang++: error: linker command failed with exit code 1 (use -v to see invocation)
      ninja: build stopped: subcommand failed.

您能帮我弄清楚我在这里缺少什么链接吗?我尝试生成一堆共享和静态库,并在此处链接它们,但仍然存在相同的错误。

我知道这是旧的,不确定它是否会有所帮助,但是在将C 应用链接到TensorFlow API时,我遇到了相同的错误,就我而言,使用了-Ltensorflow_cc -ltensorflow_framework我的主要更改是-ltensorflow_cc而不是-ltensorflow