android studio tensorflow cpp build - undefined reference

时间:2018-01-25 16:57:30

标签: android c++ android-studio tensorflow native

我从ghit下载了tensorflow, 我用我的android sdk和android ndk配置了WORKSPACE文件。

我从命令行运行./configure

我用buzel构建

bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//external:android/crosstool --cpu=armeabi-v7a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --config=android --fat_apk_cpu=armeabi-v7a --verbose_failures

构建工作正常。

当我进入Android Studio时,我将我的libtensorflow_inference.so包含在jnilibs文件夹和CMakefile.txt中。我已经包含.h文件和tendorflow依赖的所有目录。

CMakefile.txt

#include header file
#TENSORFLOW
include_directories(${pathTensorflow})
#TENSORFLOW dependeces
include_directories(${pathToWorkspace}/downloads/nsync/public)
include_directories(${pathToWorkspace}/downloads/protobuf/src)
include_directories(${pathToWorkspace}/downloads/eigen)


#include tensorflow shared library
add_library( lib_TF SHARED IMPORTED )
set_target_properties(lib_TF PROPERTIES IMPORTED_LOCATION ${pathToProject}/src/main/jnilibs/${ANDROID_ABI}/libtensorflow_inference.so)

target_link_libraries( # Specifies the target library.
                  myLibcpp

                  lib_TF

                  ...
                  )

在我的文件cpp中,我插入了这段代码

tensorflow::GraphDef graph_def;

但是当我运行make文件时,我发现了这个错误

Error:error: linker command failed with exit code 1 (use -v to see invocation)
Error:(100) undefined reference to 'tensorflow::GraphDef::GraphDef()'

1 个答案:

答案 0 :(得分:0)

我有同样的问题,我的cmake设置与你的相同,这是输出:

  

构建命令失败。   使用参数{--build \ app.externalNativeBuild \ cmake \ debug \ x86_64 --target native-lib}执行进程cmake.exe时出错

     

[1/2]构建CXX对象native-lib.cpp.o

     

[2/2]链接CXX共享库libnative-lib.so

     

失败:cmd.exe / C" cd。 &安培;&安培; x86_64-linux-android-g ++。exe --sysroot = C:/ Android / Sdk / ndk-bundle / sysroot -fPIC -isystem C:/ Android / Sdk / ndk-bundle / sysroot / usr / include / x86_64-linux- android -D__ANDROID_API __ = 23 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa, - noexecstack -Wformat -Werror = format-security -std = c ++ 14 -O0 -Wl, - exclude-libs,libgcc.a -Wl, - exclude-libs,libatomic.a --sysroot C:/ Android / Sdk / ndk-bundle / platforms / android-23 / arch-x86_64 - Wl, - build-id -Wl, - warn-shared-textrel -Wl, - fatal-warnings -Wl, - no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl, -z,现在-shared -Wl,-soname,libnative-lib.so -o .. \ native-lib.cpp.o -llog ../libs/tf_libs/x86_64/libtensorflow_inference.so -latomic -lm&#34 ; C:/ Android设备/ SDK / NDK束/源/ CXX-STL / GNU-的libstdc ++ / 4.9 /库/ x86_64的/ libgnustl_static.a" &安培;&安培; cd。"

     

\ app \ src \ main \ cpp / native-lib.cpp:15:错误:未定义引用' TF_Version'

     

collect2.exe:错误:ld返回1退出状态

     

忍者:构建已停止:子命令失败。

所以它似乎是链接库(-llog ../libs/tf_libs/x86_64/libtensorflow_inference.so),但由于某种原因无法找到符号。

我无法找到有关-llog做什么的任何信息。

我试过用gcc和clang工具链。