使用Tensorflow C++;在Android中使用CMake 我有Android应用程序,C++代码与CMake链接。我需要在C++侧加载和运行TysFraceFrand。 我使用./Tensorflow/contrib/makefile/build\u all\u android.sh脚本构建了Tensorflow。 我通过以下方式将tensorflow头文件和库添加到CMake文件中: # other libraries here add_library(lib_tf STATIC IMPORTED ) set_target_properties(lib_tf PROPERTIES IMPORTED_LOCATION /home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a) add_library(lib_proto STATIC IMPORTED ) set_target_properties(lib_proto PROPERTIES IMPORTED_LOCATION /home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/protobuf_android/armeabi-v7a/lib/libprotobuf.a) add_library(lib_proto_lite STATIC IMPORTED ) set_target_properties(lib_proto_lite PROPERTIES IMPORTED_LOCATION /home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/protobuf_android/armeabi-v7a/lib/libprotobuf-lite.a) add_library(lib_protoc STATIC IMPORTED ) set_target_properties(lib_protoc PROPERTIES IMPORTED_LOCATION /home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/protobuf_android/armeabi-v7a/lib/libprotoc.a) target_include_directories(pitools PRIVATE # Other header paths here ../../../../../../tensorflow/ ../../../../../../tensorflow/tensorflow/contrib/makefile/downloads ../../../../../../tensorflow/tensorflow/contrib/makefile/downloads/eigen ../../../../../../tensorflow/tensorflow/contrib/makefile/downloads/protobuf/src ../../../../../../tensorflow/contrib/makefile/gen/proto ../../../../../../tensorflow/tensorflow/contrib/makefile/downloads/nsync/public/ ../../../../../../tensorflow/tensorflow/contrib/makefile/gen/proto/ ) target_link_libraries( # Specifies the target library. #other libs here lib_tf lib_proto lib_proto_lite lib_protoc )

使用Tensorflow C++;在Android中使用CMake 我有Android应用程序,C++代码与CMake链接。我需要在C++侧加载和运行TysFraceFrand。 我使用./Tensorflow/contrib/makefile/build\u all\u android.sh脚本构建了Tensorflow。 我通过以下方式将tensorflow头文件和库添加到CMake文件中: # other libraries here add_library(lib_tf STATIC IMPORTED ) set_target_properties(lib_tf PROPERTIES IMPORTED_LOCATION /home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a) add_library(lib_proto STATIC IMPORTED ) set_target_properties(lib_proto PROPERTIES IMPORTED_LOCATION /home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/protobuf_android/armeabi-v7a/lib/libprotobuf.a) add_library(lib_proto_lite STATIC IMPORTED ) set_target_properties(lib_proto_lite PROPERTIES IMPORTED_LOCATION /home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/protobuf_android/armeabi-v7a/lib/libprotobuf-lite.a) add_library(lib_protoc STATIC IMPORTED ) set_target_properties(lib_protoc PROPERTIES IMPORTED_LOCATION /home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/protobuf_android/armeabi-v7a/lib/libprotoc.a) target_include_directories(pitools PRIVATE # Other header paths here ../../../../../../tensorflow/ ../../../../../../tensorflow/tensorflow/contrib/makefile/downloads ../../../../../../tensorflow/tensorflow/contrib/makefile/downloads/eigen ../../../../../../tensorflow/tensorflow/contrib/makefile/downloads/protobuf/src ../../../../../../tensorflow/contrib/makefile/gen/proto ../../../../../../tensorflow/tensorflow/contrib/makefile/downloads/nsync/public/ ../../../../../../tensorflow/tensorflow/contrib/makefile/gen/proto/ ) target_link_libraries( # Specifies the target library. #other libs here lib_tf lib_proto lib_proto_lite lib_protoc ),android,c++,tensorflow,cmake,Android,C++,Tensorflow,Cmake,目前我只是尝试创建NewSession并加载图表。目前代码很简单: 包括此标题 #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/public/session.h" #include "tensorflow/core/util/stat_summarizer.h" 并创建了如下会话: tensorflow::SessionOptions options; options.config.set_inte

目前我只是尝试创建NewSession并加载图表。目前代码很简单: 包括此标题

#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/util/stat_summarizer.h"
并创建了如下会话:

tensorflow::SessionOptions options;
options.config.set_inter_op_parallelism_threads(0);
options.config.set_use_per_session_threads(false);
options.config.set_intra_op_parallelism_threads(0);
options.config.set_allow_soft_placement(false);
options.config.set_log_device_placement(false);
tensorflow::Status status = tensorflow::NewSession(options, &_session);
/home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(config.pb.o):config.pb.cc:function std::string::_Rep::_M_dispose(std::allocator<char> const&) [clone .part.1]: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(config.pb.o):config.pb.cc:function void google::protobuf::internal::RepeatedPtrFieldBase::Clear<google::protobuf::RepeatedPtrField<std::string>::TypeHandler>() [clone .isra.161]: error: undefined reference to 'std::string::_M_mutate(unsigned int, unsigned int, unsigned int)'
/home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(config.pb.o):config.pb.cc:function void google::protobuf::internal::RepeatedPtrFieldBase::Destroy<google::protobuf::RepeatedPtrField<std::string>::TypeHandler>() [clone .isra.160]: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(config.pb.o):config.pb.cc:function void google::protobuf::internal::RepeatedPtrFieldBase::Destroy<google::protobuf::RepeatedPtrField<std::string>::TypeHandler>() [clone .isra.160]: error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
/home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(config.pb.o):config.pb.cc:function protobuf_tensorflow_2fcore_2fprotobuf_2fconfig_2eproto::protobuf_AssignDescriptors(): error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
当我尝试在Android Studio中创建项目时,会出现如下链接器错误:

tensorflow::SessionOptions options;
options.config.set_inter_op_parallelism_threads(0);
options.config.set_use_per_session_threads(false);
options.config.set_intra_op_parallelism_threads(0);
options.config.set_allow_soft_placement(false);
options.config.set_log_device_placement(false);
tensorflow::Status status = tensorflow::NewSession(options, &_session);
/home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(config.pb.o):config.pb.cc:function std::string::_Rep::_M_dispose(std::allocator<char> const&) [clone .part.1]: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(config.pb.o):config.pb.cc:function void google::protobuf::internal::RepeatedPtrFieldBase::Clear<google::protobuf::RepeatedPtrField<std::string>::TypeHandler>() [clone .isra.161]: error: undefined reference to 'std::string::_M_mutate(unsigned int, unsigned int, unsigned int)'
/home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(config.pb.o):config.pb.cc:function void google::protobuf::internal::RepeatedPtrFieldBase::Destroy<google::protobuf::RepeatedPtrField<std::string>::TypeHandler>() [clone .isra.160]: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(config.pb.o):config.pb.cc:function void google::protobuf::internal::RepeatedPtrFieldBase::Destroy<google::protobuf::RepeatedPtrField<std::string>::TypeHandler>() [clone .isra.160]: error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
/home/hhov/github/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(config.pb.o):config.pb.cc:function protobuf_tensorflow_2fcore_2fprotobuf_2fconfig_2eproto::protobuf_AssignDescriptors(): error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
上述命令的错误为:

ERROR: /home/hhov/.cache/bazel/_bazel_hhov/7cd939709f31bed648236b7a888c061b/external/double_conversion/BUILD.bazel:7:1: C++ compilation of rule '@double_conversion//:double-conversion' failed (Exit 1): false failed: error executing command 
  (cd /home/hhov/.cache/bazel/_bazel_hhov/7cd939709f31bed648236b7a888c061b/execroot/org_tensorflow && \
  exec env - \
    PWD=/proc/self/cwd \
    PYTHON_BIN_PATH=/usr/bin/python \
    PYTHON_LIB_PATH=/usr/local/lib/python2.7/dist-packages \
    TF_DOWNLOAD_CLANG=0 \
    TF_NEED_CUDA=0 \
    TF_NEED_OPENCL_SYCL=0 \
  /bin/false -MD -MF bazel-out/armeabi-v7a-opt/bin/external/double_conversion/_objs/double-conversion/external/double_conversion/double-conversion/diy-fp.pic.d '-frandom-seed=bazel-out/armeabi-v7a-opt/bin/external/double_conversion/_objs/double-conversion/external/double_conversion/double-conversion/diy-fp.pic.o' -fPIC -iquote external/double_conversion -iquote bazel-out/armeabi-v7a-opt/genfiles/external/double_conversion -iquote external/bazel_tools -iquote bazel-out/armeabi-v7a-opt/genfiles/external/bazel_tools -isystem external/double_conversion -isystem bazel-out/armeabi-v7a-opt/genfiles/external/double_conversion -isystem bazel-out/armeabi-v7a-opt/bin/external/double_conversion -c external/double_conversion/double-conversion/diy-fp.cc -o bazel-out/armeabi-v7a-opt/bin/external/double_conversion/_objs/double-conversion/external/double_conversion/double-conversion/diy-fp.pic.o)
Target //tensorflow/contrib/android:libtensorflow_inference.so failed to build
完整错误消息的Google驱动器链接:

你能告诉我我做错了什么,或者如果这不是正确的方法,那么你能提供一些步骤如何做到这一点吗

谢谢,
hhov

请在问题帖子中添加错误消息(以文本形式)。如果发现完整生成日志太长,请添加至post至少第一条错误消息。链接器错误看起来像是缺少STL。尝试将
set(CMAKE_CXX_FLAGS“${CMAKE_CXX_FLAGS}-std=c++11”)
添加到您的CMAKE脚本中。@Tsyvarev我添加了第一条错误消息。@JamesPoag我这样设置它:set(CMAKE_CXX_FLAGS“${CMAKE_CXX_FLAGS}-std=c++14-fexceptions-frti-ffast math-Wno showing-O3”)