Google Project Tango NDK undefined reference on functions

痴心易碎 提交于 2019-12-08 12:06:51

问题


I am getting a compile error:

undefined reference to 'TangoService_getConfig' (MoreTeapotsNativeActivity.cpp)

ld returned 1 exit status (collect2.exe)

I am working with the tango sdk TangoSDK_Ikariotikos_C.zip in Visual Studio 2015 using VisualGDB. I have also replicated the error in Android Studio so it isn't IDE specific.

I have started with an NDK sample project to test a native activity deploys correctly and reduce complexity whilst troubleshooting. I have used VisualGDB MoreTeaPotsNativeActivity but any will do. The app compiles and runs on our ASUS Zenfone AR. Once I include tango_client_api.h and add the following code, I get the compile error:

TangoCoordinateFramePair* Tango_FramePair;
Tango_FramePair = new TangoCoordinateFramePair();
Tango_FramePair->base = TANGO_COORDINATE_FRAME_START_OF_SERVICE;
Tango_FramePair->target = TANGO_COORDINATE_FRAME_DEVICE;
TangoErrorType retval;
// Connect to tango service.
TangoConfig tango_config;
tango_config = TangoService_getConfig(TANGO_CONFIG_DEFAULT);

The Tango header file has an extern "C" wrapper for the C functions and the .o shows them demangled so I can't see why it is failing.
If I comment out...

//tango_config = TangoService_getConfig(TANGO_CONFIG_DEFAULT);

...it compiles and the enums show as locals in the debug so it seems to be a problem with functions: see image of locals here

I may be missing something glaringly obvious because android is fairly new to me. Perhaps someone can test the tangoSDK library with the same code block and spot the issue. It is frustrating that I cannot even link a library. I may be missing something simple but to me it is not obvious.

Any help will be greatly appreciated.


回答1:


I contacted Sysprogs Support who gave me a link: PREBUILT_SHARED_LIBRARY syntax

I hadn't realised the library wasn't being copied even though intellisense was reading the header. I needed to include a reference in the make file (android.mk) to copy the library (I copied Tango include and lib folders to the project jni folder):

include $(CLEAR_VARS)

LOCAL_MODULE          := tango_client_api
LOCAL_SRC_FILES := ../jni/lib/$(TARGET_ARCH_ABI)/libtango_client_api.so

include $(PREBUILT_SHARED_LIBRARY)

I did the same with an additional block for the support library:

include $(CLEAR_VARS)

LOCAL_MODULE          := tango_support_api
LOCAL_SRC_FILES := ../jni/lib/$(TARGET_ARCH_ABI)/libtango_support_api.so

include $(PREBUILT_SHARED_LIBRARY)

The main module just needs this:

LOCAL_SHARED_LIBRARIES := tango_client_api

The whole file looks like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE          := tango_client_api
LOCAL_SRC_FILES := ../jni/lib/$(TARGET_ARCH_ABI)/libtango_client_api.so

include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE          := tango_support_api
LOCAL_SRC_FILES := ../jni/lib/$(TARGET_ARCH_ABI)/libtango_support_api.so

include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := MoreTeapotsNativeActivity
#VisualGDBAndroid: AutoUpdateSourcesInNextLine
LOCAL_SRC_FILES := gdbserver_launcher.c MoreTeapotsNativeActivity.cpp MoreTeapotsRenderer.cpp
LOCAL_C_INCLUDES := jni/include

LOCAL_LDLIBS    := -llog -landroid -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := cpufeatures android_native_app_glue ndk_helper
LOCAL_SHARED_LIBRARIES := tango_client_api


include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/ndk_helper)
$(call import-module,android/native_app_glue)
$(call import-module,android/cpufeatures)

I didn't get this to work straight away when following the NDK examples but Sysprogs gave me feedback on my mistake which I will include.

I tried to include:

LOCAL_MODULE_FILENAME := tango_client_api 

I left off the lib and .so as seemed to be convention. The .so was not necessary but taking lib off was changing the file name which caused a link error. That said, that line was unnecessary in the first place to I removed it. Then it removed the error relating to this. I have yet to see if the library works at runtime because I now get this error:

java.lang.UnsatisfiedLinkError: Unable to load native library "/data/app/com.sample.moreteapots-2/lib/arm64/libMoreTeapotsNativeActivity.so": dlopen failed: library "libbinder.so" not found

But this seems to relate to a problem with Android 7.0 platform 24 and higher where

the system prevents apps from dynamically linking against non-NDK libraries

from /Android/android-sdk/docs/about/versions/nougat/android-7.0-changes.html



来源:https://stackoverflow.com/questions/46097054/google-project-tango-ndk-undefined-reference-on-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!