I have native source code written in C that I would like to run on my Android device (Nexus 7). I already successfully did lots of research and online tutorials on running native code on Android using Android NDK. I gained quite some knowledge on this. However, the code that I have makes use of the complex functionalities of the standard math library, defined in complex.h. The NDK C library however does not seem to support the complex functionalities. Whenever I do an ndk-build on the project I get:
fatal error: complex.h: no such file or directory.
As a solution I thought of getting the standard math library (libm.a) from arm-linux-gnueabi and link it with my native source. Here is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := StandardC
LOCAL_SRC_FILES := libc.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := mathLib
LOCAL_SRC_FILES := libm.a
LOCAL_STATIC_LIBRARIES := StandardC
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ComplexOperations
LOCAL_SRC_FILES := libComplexOperations.a
LOCAL_STATIC_LIBRARIES := mathLib
LOCAL_C_INCLUDES += /usr/arm-linux-gnueabi/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := MySource
LOCAL_CFLAGS += -std=c99
LOCAL_SRC_FILES := com_samuel_test_ComplexOperationsLib.c
LOCAL_C_INCLUDES += /usr/arm-linux-gnueabi/include
LOCAL_STATIC_LIBRARIES := ComplexOperations
include $(BUILD_SHARED_LIBRARY)
I had to link the libc of the arm-linux-gnueabi-gcc as well as libm needs it. The "ComplexOperations" module was statically compiled using arm-linux-gnueabi-gcc with compiler flags -march=armv7-a. This library makes use of complex.h. This builds without any errors and warnings. But when I run the application and call
System.loadLibrary("MySource");
I get this error on logcat:
E/dalvikvm( 3932): dlopen("/data/app-lib/com.samuel.test-1/libMySource.so") failed: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol ".LANCHOR2" referenced by "libMySource.so"...
On this error an UnsatisfiedLinkError exception is thrown which causes the application to crash if not handled.
Can somebody PLEAASEE help me out!! I've already tried figuring this out myself for days!! :(
complex.h
? – Nickolenicks