Android NDK failed with libutils.so: undefined reference to `__pthread_gettid' - android-ndk

I try to make my android application with a native shared library but I get below error:
Debug//local/arm64-v8a/libutils.so: undefined reference to `__pthread_gettid' clang++: error: linker command failed with exit code 1 (use -v to see invocation)
I'm using Android NDK r13b. In my makefile have:
Application.mk
.....
APP_PLATFORM := android-19
APP_ABI := arm64-v8a
.....
Android.mk
.....
include $(CLEAR_VARS)
LOCAL_MODULE := libutils
LOCAL_SRC_FILES := $(APP_ABI)/libutils.so <= already 64bit lib
include $(PREBUILT_SHARED_LIBRARY)
.....

__pthread_gettid is not an NDK API. It's in the LIBC_PRIVATE version section: https://android.googlesource.com/platform/bionic/+/master/libc/libc.map.txt#1481

Related

cocos2d-x and run in android Studio

i will run a cocos project in android Studio but when type command cocos compile -p android in cmd.exe say error in ndk.
and android.mk is :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END
LOCAL_STATIC_LIBRARIES := cocos2dx_static
# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END
my cmd
As now According to me you are using NDK 12 or greater.
These NDK by default add arm64-v8a architecture support. You don't have libfreetype.a file in cocos2d/external/freetype2/prebuilt/android/arm64-v8a/ folder because cocos2d not generate by default, it slow down the compiling speed.
Solution is you can use NDK 11 or lesser
otherwise use latest version of cocos2d-x and enable ABI support to all arch armeabi armeabi-v7a x86 arm64-v8a instead of armeabi only
Some of concerning topic/issue
https://github.com/cocos2d/cocos2d-x/issues/15713
https://github.com/cocos2d/cocos2d-x/issues/15566

ndk-build using amadillo (blas lapack) and vlfeat lib

I am trying to compile c++ code written using armadillo that I have uncomment blas lapack in config.hpp and also vlfeat (vl.so) in Andriod make file.
In Jni folder I have the following Andriod.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
PRODUCT_PACKAGES += \libblas
PRODUCT_PACKAGES += \liblapack
PRODUCT_PACKAGES += \libvl
include $(CLEAR_VARS)
LOCAL_MODULE+=mjni
LOCAL_SRC_FILES+=HelloJNI.cpp
LOCAL_SRC_FILES+=featureExtraction.cpp
LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/include/externalInclude/
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/include/externalInclude/armadillo_bits
#LOCAL_SHARED_LIBRARIES := blas lapack
LOCAL_LDLIBS += -llog -ldl
LOCAL_CPP_FEATURES += exceptions
LOCAL_CPPFLAGS += -fexceptions
include $(BUILD_SHARED_LIBRARY)
for each module blas, lapack, and vlfeat I used .so libraries as follows:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libvl
MY_LIBRARY_NAME := libvl
### export include path
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/vl
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/../include/src
### path to library
LOCAL_SRC_FILES := libvl.so
### export dependency on the library
LOCAL_EXPORT_LDLIBS += -l$(MY_LIBRARY_NAME)
include $(PREBUILT_SHARED_LIBRARY)
and
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libblas
MY_LIBRARY_NAME := libblas
### export include path
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/OpenBLAS/include
### path to library
LOCAL_SRC_FILES := libblas.so
### export dependency on the library
LOCAL_EXPORT_LDLIBS += -l$(MY_LIBRARY_NAME)
include $(PREBUILT_SHARED_LIBRARY)
I have got the following errors when I use ndk-build command:
jni/include/externalInclude/armadillo_bits/blas_wrapper.hpp:172: error: undefined reference to 'sdot_'
jni/include/externalInclude/armadillo_bits/blas_wrapper.hpp:98: error: undefined reference to 'ssyrk_'
jni/include/externalInclude/armadillo_bits/blas_wrapper.hpp:28: error: undefined reference to 'sgemv_'
jni/include/externalInclude/armadillo_bits/blas_wrapper.hpp:63: error: undefined reference to 'sgemm_'
error: undefined reference to 'vl_sift_new'
error: undefined reference to 'vl_sift_process_first_octave'
error: undefined reference to 'vl_sift_delete'
error: undefined reference to 'vl_sift_detect'
error: undefined reference to 'vl_sift_calc_keypoint_orientations'
error: undefined reference to 'vl_sift_calc_keypoint_descriptor'
error: undefined reference to 'vl_sift_process_next_octave'
i had the same problem and after some struggleing i found a sulotion
go to http://danilogiulianelli.blogspot.co.il/2013/02/how-to-build-gcc-fortran-cross-compiler.html and build the gcc cross compiler . i did it for ndk-8d.
make sure that after running the script you can see the 2 folders that the script created in
android-ndk-r8d\toolchains\arm-linux-androideabi-4.8.0
android-ndk-r8b\android-ndk-r8d\toolchains\x86-4.8.
download blas lib and update the following field in blas make.in:
instead of
FORTRAN = gfortran
FORTRAN = $(yourPath)/android-ndk-r8d/toolchains/x86-4.8.0/prebuilt/linux-x86/bin/i686-linux-android-gfortran
run the makefile.
add in you android.mk and add the following localflags
LOCAL_LDFLAGS := $(OPT) $(PROF) -lblas -llapack -lstdc++ -lgfortran
run ndk-build
i had problem with ndk-8d that had missing files of gcc 4.8, in order to solve it i copied the missing files from ndk-9 and it works.

HERE Map armeabi-v7a libraries removed when im adding armeabi file(C library) Is there something missing with my Android.mk file?

Hello i'm new to NDK and C/C++ development with android application. i'm having problem in my android application in compiling android application with c/c++.. I added some custom libraries for my sqlite. Could anyone explain what's happening to my project and is there something that i need to configure with my MK file? i added this to my mk file APP_ABI := armeabi armeabi-v7a
Here is my Android.mk file
APP_PLATFORM := android-8
#WHAT DO I NEED..
APP_ABI := armeabi armeabi-v7a
#TARGET_ARCH = arm
#TARGET_ARCH_ABI = armeabi-v7a
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ExtFunc
LOCAL_SRC_FILES := extension-functions.c
LOCAL_SRC_FILES += sqlite3.c
LOCAL_SHARE_LIBRARIES := sqlite3
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ProximityAPI
LOCAL_SRC_FILES := ProximitySearch.c
LOCAL_SRC_FILES += sqlite3.c
LOCAL_SHARE_LIBRARIES := sqlite3
include $(BUILD_SHARED_LIBRARY)
When i started running my project the armeabi-v7a libraries
automatically removed in compilation.
I used NDK R10b
To make things clear the two library is working in different project but when i combine them it removed my HERE-Map Libraries under the armeabi-v7a in compiling my android application.
Hope someone could help me i'm confused..
Thanks!
APP_ABI should go into your Application.mk file within the jni folder. It might not exist by default so you might have to create one. Also, if you are building only for ARM there is no need to specify that explicitly. If you are looking to target multiple architecture like x86 you could add that to you APP_ABI parameter.

Android NDK thrid party static library - ndk build giving error : jni/libAT_int.a:1:1: invalid character

I'm trying to integrate static library libAT_int.a
I have successfully integrated it in iOS app.
lipo -info libAT_int.a
Architectures in the fat file: libAT_int.a are: armv6 armv7
But when i'm integrating it with Android NDK. I'm getting error during ndk build
error: jni/libAT_int.a:1:1: invalid character
Android.mk has following content :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := AT
ifeq ($(APP_ABI), armeabi-v7a)
LOCAL_SRC_FILES := libAT_int.a
else
LOCAL_SRC_FILES := libAT_int.a
endif
LOCAL_CPP_FEATURES += rtti exceptions
LOCAL_CPP_EXTENSION := .cpp .h
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := MusicSDK
LOCAL_SRC_FILES := MusicSDK.cpp
LOCAL_CPP_FEATURES += rtti exceptions
LOCAL_CPP_EXTENSION := .cpp .h
LOCAL_STATIC_LIBRARIES := AT
include $(BUILD_SHARED_LIBRARY)
You can't use a static library built for iOS when building for Android, you need a static library built specifically for Android.

NDK profiling showing ".so has no symbols"

I am doing NDK profiling for my project using android-ndk-profiler-3.1. I have made changes in Android.mk as follows...
LOCAL_PATH := $(call my-dir)
-include android-ndk-profiler.mk
include $(CLEAR_VARS)
# Module name -------------------------------------------------------
LOCAL_CFLAGS += -O3
TARGET_ARCH_ABI :=armeabi
LOCAL_CFLAGS := -pg
LOCAL_STATIC_LIBRARIES := andprof
LOCAL_LDLIBS += -llog
LOCAL_MODULE := libitv
include $(BUILD_SHARED_LIBRARY)
Application.mk is as follows...
APP_ABI := armeabi
APP_PLATFORM := android-10
I have called monstartup("itv.so"); function in the beginning of the native code and moncleanup(); function in the stop method. And gmon.out file is created successfully.And then I have pasted gmon.out in
D:\android\android-ndk-r6-windows\android-ndk-r6\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin directory.
But when I am trying to read gmon.out using the following command...
D:\android\android-ndk-r6-windows\android-ndk-r6\toolchains\arm-linux-androideab
i-4.4.3\prebuilt\windows\bin>arm-linux-androideabi-gprof D:\InternetTV_FD_Canvas
\libs\armeabi\libitv.so > out.txt
This Error is showing...
arm-linux-androideabi-gprof: file `D:\InternetTV_FD_Canvas\libs\armeabi\libitv.so'
has no symbols
I am not able to make out why this error is coming even I have done everything fine.
Can anybody please help me.
Any help will be appreciated.
Thanks in Advance.
The NDK build process creates 2 libraries, one with symbols and one stripped without. You install the stripped, symbol-less library in your APK, but you need to use the unstripped version with gprof. If you run:
arm-linux-androideabi-gprof D:\InternetTV_FD_Canvas\obj\local\armeabi\libitv.so
... then that should be the correct library.

Resources