android Tensorflow未定义对“tensorflow::Scope::NewRootScope()”的引用

8iwquhpp  于 2023-06-20  发布在  Android
关注(0)|答案(1)|浏览(110)

我已经为多种架构交叉编译了tensorflow的android build,android中的编译是通过使用CMake的gradle触发的(通过CMakeLists.txt)。在cmake文件中,我添加了以下内容:

  1. # Link our new shared lib to its dependencies
  2. set(libs_DIR $ENV{HOME}/tensorflow_gens/${ANDROID_ABI})
  3. target_link_libraries(
  4. tensorflow
  5. ${libs_DIR}/libandroid_tensorflow_kernels.lo
  6. ${libs_DIR}/libandroid_tensorflow_lib_lite.lo
  7. ${libs_DIR}/libandroid_tensorflow_lib.lo
  8. ${libs_DIR}/libtensorflow-core.a
  9. ${libs_DIR}/libprotobuf.a
  10. ${libs_DIR}/libprotobuf_lite.a
  11. ${libs_DIR}/libprotos_all_cc_impl.a
  12. ${libs_DIR}/libnsync.a
  13. ${libs_DIR}/nsync.a
  14. android
  15. log
  16. m
  17. z
  18. )

但我最终得到了一堆未找到的错误消息,如下所示:

  1. Execution failed for task ':tensorflow:externalNativeBuildDebug'.
  2. > Build command failed.
  3. Error while executing process
  4. /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}
  5. [1/2] Building CXX object CMakeFiles/tensorflow.dir/src/main/cpp/tensorflow-lib.cpp.o
  6. [2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi/libtensorflow.so
  7. FAILED: : && /Users/xxxx/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++
  8. --target=armv5te-none-linux-androideabi
  9. --gcc-toolchain=/Users/xxxx/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
  10. --sysroot=/Users/xxxx/Library/Android/sdk/ndk-bundle/sysroot -fPIC
  11. -isystem /Users/Sujit/xxxx/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi
  12. -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong
  13. -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack
  14. -Wformat -Werror=format-security -frtti -fexceptions -std=c++11 -fpic -DTF_LEAN_BINARY -DGOOGLE_PROTOBUF_NO_RTTI
  15. -DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER -O0 -fno-limit-debug-info
  16. -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot
  17. /Users/xxxx/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm
  18. -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined
  19. -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now
  20. -Wl,--allow-multiple-definition
  21. -Wl,--whole-archive -shared -Wl,-soname,libtensorflow.so -o
  22. ../../../../build/intermediates/cmake/debug/obj/armeabi/libtensorflow.so
  23. CMakeFiles/tensorflow.dir/src/main/cpp/tensorflow-lib.cpp.o
  24. /Users/xxxx/work/tensorflow_gens/armeabi/libandroid_tensorflow_kernels.lo
  25. /Users/xxxx/work/tensorflow_gens/armeabi/libandroid_tensorflow_lib_lite.lo
  26. /Users/xxxx/work/tensorflow_gens/armeabi/libandroid_tensorflow_lib.lo
  27. /Users/xxxx/work/tensorflow_gens/armeabi/libtensorflow-core.a
  28. /Users/xxxx/work/tensorflow_gens/armeabi/libprotobuf.a
  29. /Users/xxxx/work/tensorflow_gens/armeabi/libprotobuf_lite.a
  30. /Users/xxxx/work/tensorflow_gens/armeabi/libprotos_all_cc_impl.a
  31. /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" && :
  32. /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:39: error: undefined reference to 'tensorflow::Scope::NewRootScope()'
  33. /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:40: error: undefined reference to 'tensorflow::ClientSession::ClientSession(tensorflow::Scope const&)'
  34. /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)'
  35. /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'
  36. /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:47: error: undefined reference to 'tensorflow::ClientSession::~ClientSession()'
  37. /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:47: error: undefined reference to 'tensorflow::Scope::~Scope()'
  38. /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:47: error: undefined reference to 'tensorflow::ClientSession::~ClientSession()'
  39. /Users/xxxx/work/TestIntegrateTensorflow/tensorflow/src/main/cpp/tensorflow-lib.cpp:47: error: undefined reference to 'tensorflow::Scope::~Scope()'
  40. /Users/xxxx/work/tensorflow_gens/includes/tensorflow/cc/framework/ops.h:245: error: undefined reference to 'tensorflow::Operation::Operation(tensorflow::Node*)'
  41. clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  42. ninja: build stopped: subcommand failed.

你能帮我弄清楚我在这里缺少什么链接吗?我试过生成一堆共享的静态库,并将它们链接到这里,但仍然遇到同样的错误。

2sbarzqh

2sbarzqh1#

我知道这是旧的,不确定它是否会有帮助,但我在将我的C++应用程序链接到tensorflow API时遇到了同样的错误,在我的情况下,使用-ltensorflow_cc -ltensorflow_framework就足够了我的主要更改是-ltensorflow_cc而不是-ltensorflow

相关问题