NDK cannot locate symbol "_Znwj" - android

I've compiled a 3rd party library on Linux using a standalone toolchain, and I'm now trying to load that library in my app.
Problem is I'm getting java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_Znwj" referenced by "libmxnet_predict.so"
I've tried adding CFLAGS and LDFLAGS, both APP & LOCAL, but to no avail.
Before you ask, I'm developing with ADT because I have to.
This is my Application.mk:
APP_STL := gnustl_shared
APP_CFLAGS += -std=c++11
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-19
My (simplified) Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE:=SHARED
OPENCV_CAMERA_MODULES:=off
OPENCV_INSTALL_MODULES:=on
NDK_TOOLCHAIN_VERSION=4.9
include $(CLEAR_VARS)
include $(PREBUILT_SHARED_LIBRARIES)
include C:/OpenCV-2.4.8-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := FreshubML
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_SRC_FILES := Mldevlib.cpp \
Tablet.cpp \
Interface.cpp \
LOCAL_LDLIBS += -llog -ldl -landroid -lm -ljnigraphics -lstdc++
C:\KitchenVision\Workspaces\MLDevWorkspace\MLDev\assets\share
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libmxnet_predict
LOCAL_SRC_FILES := lib/armeabi-v7a/libmxnet_predict.so
include $(PREBUILT_SHARED_LIBRARY)
Searching the standalone toolchain I saw that the symbol was referenced in libgnust_shared.so which I added to my project via APP_STL and in libstdc++.so but still, same error.
How do I get this to work?

Related

I am getting error while ndk build in android.mk file

I am getting error during ndk build. I have only one android.mk file and only one Application.mk file in my project
Android NDK: Trying to define local module 'protobuf' in /home/parag.j/AndroidArm//jni/Android.mk.
Android NDK: But this module was already defined by /home/parag.j/AndroidArm//jni/Android.mk.
Here is my Android.mk file
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE=ndktest
LOCAL_SRC_FILES=ndktest.cpp
include $(CLEAR_VARS)
LOCAL_MODULE := c++_shared
LOCAL_SRC_FILES := $(LOCAL_PATH)/inc/build/libc++_shared.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := armnn
LOCAL_SRC_FILES := $(LOCAL_PATH)/inc/build/libarmnn.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := armnnTfParser
LOCAL_SRC_FILES := $(LOCAL_PATH)/inc/build/libarmnnTfParser.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := protobuf
LOCAL_SRC_FILES := $(LOCAL_PATH)/inc/build/libprotobuf.so
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_LDLIBS += -lm -llog -landroid
LOCAL_CFLAGS += -DARM_NEON_64BIT -O3 -mfpu=neon -mcpu=kryo -std=c++14 -pie
LOCAL_SHARED_LIBRARIES := opencv_java3 armnn armnnTfParser protobuf c++_shared
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc/include\
include $(BUILD_SHARED_LIBRARY)
Here is my Application.mk file
APP_ABI:=arm64-v8a
APP_CFLAGS += -Ofast
APP_OPTIM := release
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_PLATFORM := android-22
ANDROID_TOOLCHAIN_NAME := clang++
You forgot to (re)set LOCAL_MODULE for the last part of your makefile. I think the last few lines should be:
LOCAL_MODULE=ndktest
LOCAL_SRC_FILES=ndktest.cpp
LOCAL_LDLIBS += -lm -llog -landroid
LOCAL_CFLAGS += -DARM_NEON_64BIT -O3 -mfpu=neon -mcpu=kryo -std=c++14 -pie
LOCAL_SHARED_LIBRARIES := opencv_java3 armnn armnnTfParser protobuf c++_shared
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc/include
include $(BUILD_SHARED_LIBRARY)
(and get rid of the ndktest lines at the start of the file, of course)

Android NDK linking, "undefined reference" When linking with a Static Lib

Environment
android-ndk-r10c
VisualGDB
Windows x64
Use-case 1
ADB Cmdline executable ( no Java / APK ) is consist of several C++ files
Executable is compiled having "APP_STL := gnustl_static" at Application.mk
Executable is successfully compiled and running
Use-case 2
The ADB tool of Use-case 1 is split into two separate projects
A static library encapsulating general purpose functionality
The ADB Tool minus the functionality moved out to the static lib
Executable & static Lib are compiled having "APP_STL := gnustl_static" at Application.mk
ADB Exe is compiled having LOCAL_LDLIBS := -L$(PATH_TO_STATIC_LIB) -lstaticlib
Compilation fail with "undefined reference to `std::terminate()'" Linker error
Problem at hand
When compiling all CPP files as one project all goes fine, no linker error.
When spiting the logic into a thin executable and a staticlib (that the executable is linked against ) I get an "undefined reference to `std::terminate()'" Linker error.
It seems to me as if "gnustl_static" is not linked with the executable although "APP_STL := gnustl_static" is specified...
What am I missing here? Is there any way to force 'gnustl_static' to link ?
The make files for reference:
Makefile where all files are part of the same executable (WORKING)
Application.mk
APP_STL := gnustl_static
APP_ABI := all
APP_CFLAGS := -std=gnu++11
APP_CPPFLAGS := -std=gnu++11
NDK_TOOLCHAIN_VERSION := 4.9
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ScreenCapSvc
LOCAL_SRC_FILES := ScreenCapSvc.cpp SnapshotController.cpp SimpleTCPStream.cpp SocketsServer.cpp uuids.cpp
LOCAL_C_INCLUDES :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=
LOCAL_LDLIBS := -llog
LOCAL_CFLAGS :=
LOCAL_CPPFLAGS :=
LOCAL_LDFLAGS :=
COMMON_SRC_FILES := $(LOCAL_SRC_FILES)
include $(BUILD_EXECUTABLE)
Makefiles where files are split into a static lib and executable that links against the lib
(NOT WORKING)
Executable Application.mk
APP_STL := gnustl_static
APP_ABI := all
APP_CFLAGS := -std=gnu++11
APP_CPPFLAGS := -std=gnu++11
NDK_TOOLCHAIN_VERSION := 4.9
Executable Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ScreenCapSvc
LOCAL_SRC_FILES := ScreenCapSvc.cpp SnapshotController.cpp
LOCAL_C_INCLUDES :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=
LOCAL_LDLIBS := -llog -L$(PATH_TO_STATIC_LIB) -lCollections_statis
LOCAL_CFLAGS :=
LOCAL_CPPFLAGS :=
LOCAL_LDFLAGS :=
COMMON_SRC_FILES := $(LOCAL_SRC_FILES)
include $(BUILD_EXECUTABLE)
Static Lib Application.mk
APP_STL := gnustl_static
APP_ABI := all
APP_CFLAGS := -std=gnu++11
APP_CPPFLAGS := -std=gnu++11
NDK_TOOLCHAIN_VERSION := 4.9
APP_MODULES := Collections-static Collections-shared
Static Lib Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := Collections-shared
LOCAL_SRC_FILES := SimpleTCPStream.cpp SocketsServer.cpp uuids.cpp
LOCAL_C_INCLUDES :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=
LOCAL_LDLIBS := -llog
LOCAL_CFLAGS :=
LOCAL_CPPFLAGS :=
LOCAL_LDFLAGS :=
COMMON_SRC_FILES := $(LOCAL_SRC_FILES)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := Collections-static
LOCAL_SRC_FILES := $(COMMON_SRC_FILES)
include $(BUILD_STATIC_LIBRARY)
This isn't a bug in the NDK build system, but it is an issue with how you are using it.
If you run ndk-build V=1, you see the actual commands that it tries to execute, and you'd see that it already tries to link in gnustl_static, but it links it in before linking in your own static library. The linker only tries libraries in the order they are specified on the linker command line, which means that it won't try to use the earlier specified gnustl_static library to resolve undefined references from a later library.
The correct solution here is to not use LOCAL_LDLIBS for forcing linking to a static library, but use the NDK provided infrastructure for linking to static libraries. That is, change your executable Android.mk like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ScreenCapSvc
LOCAL_SRC_FILES := ScreenCapSvc.cpp SnapshotController.cpp
LOCAL_STATIC_LIBRARIES := Collections_static
LOCAL_LDLIBS := -llog
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_MODULE := Collections_static
LOCAL_SRC_FILES := $(PATH_TO_STATIC_LIB)/libCollections_static.a
include $(PREBUILT_STATIC_LIBRARY)
This way, you include the static library into the build of the executable in the same way regardless if the static library is built as part of the same build, or is a prebuilt library.
This syntax also allows you to add LOCAL_EXPORT_C_INCLUDES in the section for the static library, to add the right include path when building the executable, without having to manually add it to section for the executable.
It appears that indeed although "APP_STL := gnustl_static" is strictly specified at Application.mk of the Executable it is not really linked, to force gnustl_static to link I have added the following to LOCAL_LDLIBS of Android.mk
LOCAL_LDLIBS += -L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/$(TARGET_ARCH_ABI) -lgnustl_static
Seems to me like a bug in the NDK build system...

Android OpenCV - "error: cannot find -lopencv_java"

I'm trying to develope a native code with OpenCV using IntelliJ IDEA 13.1.4. When I try to ndk-build the code provided in mixedprocessing sample, I have this error:
[armeabi-v7a] Compile++ thumb: com_sample_jniLib <= com_sample_jniLib.cpp
[armeabi-v7a] SharedLibrary : libcom_sample_jniLib.so
D:/Workspace/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lopencv_java
make.exe: *** [obj/local/armeabi-v7a/libcom_voxar_tracker_TrackerLib.so] Error 1
D:\Workspace\android-ndk-r10\sources\cxx-stl\stlport\stlport
Basically, he can't find -lopencv_java.
Here is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include jni/opencv/OpenCV.mk
LOCAL_SRC_FILES := com_voxar_tracker_TrackerLib.cpp
LOCAL_MODULE := com_voxar_tracker_TrackerLib
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
And my Application.mk:
APP_STL := stlport_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all
As I told before, I'm using IntelliJ IDEA 13.1.4, OpenCV 2.4.9 and Android NDK r10 32-bit on Windows 8.1. Does anybody have any idea of what that could be?
You seem to have forgot OPENCV_INSTALL_MODULES:=on in your Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES:=on
include jni/opencv/OpenCV.mk
LOCAL_SRC_FILES := com_voxar_tracker_TrackerLib.cpp
LOCAL_MODULE := com_voxar_tracker_TrackerLib
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)

Android NDK. 'abs' was not declared in this scope

Cant build with using gnustl_static. Got:
'abs' was not declared in this scope
And when trying to build with stlport I cant use c++11 methods.
Here is my Application.mk:
APP_ABI := armeabi-v7a
APP_STL := gnustl_static
APP_CPPFLAGS += -std=c++11 -w
APP_PLATFORM := android-19
APP_OPTIM := release
And Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ModuleName
LOCAL_LDLIBS := -lm -llog -landroid
LOCAL_C_INCLUDES := .......
LOCAL_SRC_FILES += .......
include $(BUILD_SHARED_LIBRARY)

NativeActivity using C++

I'm trying to only use c++ to porting all my apps on Android devices from IOS and from ANDROID with JAVA EGL.
One thing I just met is "fatal error: android_native_app_glue.h: No such file or directory" so I'm going over my make file , 'Android.mk' below
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_DEFAULT_CPP_EXTENSION := cpp
LOCAL_MODULE := StarEngine
LOCAL_SRC_FILES := \
main.cpp \
StarEngine.cpp \
../../../StarEngine/StarShader.cpp \
../../../StarEngine/StarTexture.cpp \
../../../StarEngine/StarFBO.cpp\
../../../StarEngine/StarTimer.cpp\
../../../StarEngine/StarMath/Matrix.cpp\
../../../StarEngine/StarMath/Random.cpp\
../../../StarEngine/StarMath/Transform.cpp\
../../../StarEngine/StarMath/Vector.cpp\
../../../StarEngine/StarMath/neonmath/neon_matrix_impl.cpp\
../../../StarEngine/StarMath/vfpmath/matrix_impl.cpp\
../../../StarEngine/StarMath/vfpmath/utility_impl.cpp\
#../../../StarEngine/StarSound/StarSound.cpp
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_CFLAGS := -D_ARM_ARCH_7=1
LOCAL_CPPFLAGS := -D_ARM_ARCH_7=1
else
endif
LOCAL_CFLAGS := -DCONFIG_EMBEDDED -DUSE_IND_THREAD -marm -mfpu=neon -mfloat-abi=softfp
APP_STL := stlport_static
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -ldl -lGLESv2 -landroid -lEGL -lGLESv1_CM
LOCAL_STATIC_LIBRARIES := android_native_app_glue cpufeatures
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cpufeatures,android/native_app_glue)
Answer :
When you use more than two static libraries you should put import-module more than twice like this
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
$(call import-module,cpufeatures)
According to the reference in NDK folder :
import-module
A function that allows you to find and include the Android.mk
of another module by name. A typical example is:
$(call import-module,<name>)
And this will look for the module tagged <name> in the list of
directories referenced by your NDK_MODULE_PATH environment
variable, and include its Android.mk automatically for you.

Categories

Resources