android.mk shared library not found - android

I tried to compile a shared library and an executable which use these library.
All sources and headers are in the same directory.
I use these Android.mk
==================libsample.so
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libsample
LOCAL_MODULE_TAGS = optional
LOCAL_PRELINK_MODULE := false
LOCAL_SRC_FILES := libsample.c
include $(BUILD_SHARED_LIBRARY)
=======================tstsample
include $(CLEAR_VARS)
LOCAL_MODULE := tstsample
LOCAL_SHARED_LIBRARY := libsample
LOCAL_CFLAGS :=-w
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := cmd.c main.c test.c
include $(BUILD_EXECUTABLE)
===================================
I obtained these error :
error: undefined reference to "each function of my library"
My library is compiled and put in the directory :
:
out/target/product/boadname/system/lib/
I also copied this library in the current directory. but I obtained the same error.
Do you have any suggestions?
Thanks by advance

If this was not a typo while copying your Android.mk to SO, then the following sed command should resolve your problem:
s/LOCAL_SHARED_LIBRARY/LOCAL_SHARED_LIBRARIES/

Related

ndk-build undefined reference errror

I'm using ndk-build to build a set of shared library(.so) for my android project. I configured and made the source code of C++ library(gdal-2.2.2).
everything was ok.("./configure & make & make install" was successful).
So i created my jni folder like this documentation.
but when I'm trying to use ndk-build on windows, I get a lot of error like "Undefined refrence to somthing".
I've spent a lot of time on this project. Is there someone to help me?
Thanks.
Update
I used configure like this on ubuntu 16.04:
./configure --prefix=/home/mahdi/Desktop/build/ --with-spatialite=yes --with-spatialite-soname=libspatialite.so --host=i686-linux-android CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" LIBS="-lsupc++ -lstdc++"
After make & make install step I created JNI. this is my directory.
jniwrap
jni
gdal
Android.mk
Application.mk
gdal_wrap.cpp
gdalconst_wrap.c
gnm_wrap.cpp
libgdal.a
ogr_wrap.cpp
osr_wrap.cpp
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := gdal
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/gdal/include
LOCAL_SRC_FILES := libgdal.a
LOCAL_EXPORT_LDLIBS := -lz
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdaljni
LOCAL_SRC_FILES := gdal_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdalconstjni
LOCAL_SRC_FILES := gdalconst_wrap.c
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ogrjni
LOCAL_SRC_FILES := ogr_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := osrjni
LOCAL_SRC_FILES := osr_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
Aplication.mk
APP_STL := gnustl_shared
APP_CFLAGS := Android.mk
APP_ABI := x86
APP_PLATFORM := android-14
Then I used android-ndk-r16b in windows-x86_64 but I faced with these errors like this picture:
There was a lot of "undefined reference error" that i can't show here.
Note: for making gdal Java Binding I used swig and jdk7 on my ubuntu 16.04.
When you build libgdal.a on your ubuntu machine, you must have sqlite3, which resolves #include "sqlite3.h".
These include files are enough for a static library, but to create libgdaljni.so you also need libsqlite3.a. You can cross-compile it for Android it yourself on the same ubuntu machine, but it is probably OK to get prebuilt library e.g. from https://github.com/couchbase/couchbase-lite-java-native/tree/master/vendor/sqlite/libs/android.
Copy this file (for appropriate ABI) to the same directory, and modify your Android.mk accordingly:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := sqlite3
LOCAL_SRC_FILES := libsqlite3.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdal
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/gdal/include
LOCAL_SRC_FILES := libgdal.a
LOCAL_EXPORT_LDLIBS := -lz
LOCAL_STATIC_LIBRARIES := sqlite3
include $(PREBUILT_STATIC_LIBRARY)
*continued without changes*
If you still have "undefined reference error", this could mean that some other libraries should be added.

Android : Loading pre-built library - Circular dependency dropped

I am trying to import a module into my project.
Android.mk in module:
LOCAL_PATH := $(call my-dir)
include $(CEAR_VARS)
LOCAL_MODULE := fromhere1
LOCAL_MODULE_FILENAME := fromhere1
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfromhere.so
include $(PREBUILT_SHARED_LIBRARY)
libfromhere.so is built by ndk-build
Android.mk in my project:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native
LOCAL_MODULE_FILENAME := libnative
LOCAL_SRC_FILES := native.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/
LOCAL_SHARED_LIBRARIES := fromhere1
include $(BUILD_SHARED_LIBRARY)
$(call import-module,module)
When I run ndk-build, I get error
[arm64-v8a] Compile : native <= native.c
make: Circular /home/raghuram/DS-5-Workspace/helloworld/obj/local/arm64-v8a/libnative.so <- /home/raghuram/DS-5-Workspace/helloworld/obj/local/arm64-v8a/libnative.so dependency dropped.
[arm64-v8a] SharedLibrary : libnative.so
aarch64-linux-android-g++: error: /home/raghuram/DS-5-Workspace/helloworld/obj/local/arm64-v8a/libnative.so: No such file or directory
make: *** [/home/raghuram/DS-5-Workspace/helloworld/obj/local/arm64-v8a/libnative.so] Error 1.
I don't understand why that circular dependency is arising.
I followed proper syntax.
After include $(PREBUILT_SHARED_LIBRARY) you have to clear the variable may be you are again prebuilding another library... this stuff solved my issue :)
LOCAL_PATH := $(call my-dir)
include $(CEAR_VARS)
LOCAL_MODULE := fromhere1
LOCAL_MODULE_FILENAME := fromhere1
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfromhere.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CEAR_VARS)
LOCAL_MODULE := fromhere2
LOCAL_MODULE_FILENAME := fromhere2
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfromhere2.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CEAR_VARS)
My mistake is the value of LOCAL_MODULE_FILENAME. It must be libfromhere1 instead of fromhere1.
ndk just puts .so suffix to the given name but it won't put lib prefix.
Always it is better to give name by yourself than letting ndk name it for you.
But I didn't understand why circular dependency arose because of that.

Undefined reference to opus functions while the appropriate header is included

In an effort to reduce bandwidth usage of an application, I tried to make an implementation of opus.
First, I cross-compiled the sources into a shared library. I copied the resulting .so file into an opus folder inside my jni folder. I also copied all opus header files into an include subfolder in the opus folder. Finally, I created an Android.mk file to allow the usage of this .so file in my implementation.
So my file structure is as follows:
/jni
/opus
/include
All opus header files
Android.mk
libopus.so
Android.mk
OpusEncoder.h
OpusDecoder.h
OpusEncoder.c
OpusDecoder.c
The Android.mk file in the opus subfolder has the following content:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := opus
LOCAL_SRC_FILES := jni/opus/libopus.so
LOCAL_C_INCLUDES := jni/opus/include
include $(PREBUILD_SHARED_LIBRARY)
As is recommended to expose the .so file for usage.
Now, in my implementation of the Encoder/Decoder, I import opus.h, and use the appropriate functions in order to expose them through JNI to the Java layer.
The Android.mk in my jni folder (which should build my JNI layer) is as follows:
LOCAL_PATH := $(call my-dir)
MY_DIR := $(LOCAL_PATH)
include $(CLEAR_VARS)
include jni/opus/Android.mk
APP_ABI := armeabi armeabi-v7a
LOCAL_PATH := $(MY_DIR)
LIB_PATH := $(LOCAL_PATH)/../lib
LOCAL_LDLIBS += -llog -landroid
#LOCAL_LDLIBS += $(LIB_PATH) -lopus
LOCAL_SHARED_LIBRARIES := opus
LOCAL_MODULE := OpusCodec
LOCAL_SRC_FILES := OpusEncoder.c \
OpusDecoder.c
include $(BUILD_SHARED_LIBRARY)
However, when I run the ndk-build command, I get the following 6 error messages:
error: undefined reference to 'opus_encoder_create'
error: undefined reference to 'opus_encode'
error: undefined reference to 'opus_encoder_destroy'
error: undefined reference to 'opus_decoder_create'
error: undefined reference to 'opus_decode'
error: undefined reference to 'opus_decoder_destroy'
Which are all methods exposed by opus.h in libopus.so. Any ideas?
Okay, so this all turned out to be a typographical error on my behalf.
For the keen observer, to make the prebuilt opus library, I used the call include $(PREBUILD_SHARED_LIBRARY) where it should have been include $(PREBUILT_SHARED_LIBRARY) (the difference being the T instead of D at the end of PREBUILT).
As a result, it didn't create the library that I tried to link to with LOCAL_SHARED_LIBRARIES := opus in my main Android.mk file.
So this is how I have my Android.mk file for the prebuilt library:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libopus
LOCAL_SRC_FILES := libopus.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
And this is my Android.mk file for the code I wrote:
MY_PROJECT_PATH := $(call my-dir)
LOCAL_PATH = $(MY_PROJECT_PATH)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
APP_ABI := armeabi armeabi-v7a
LOCAL_PATH = $(MY_PROJECT_PATH)
LOCAL_MODULE := OpusCodec
LOCAL_SHARED_LIBRARIES := libopus
LOCAL_LDLIBS += -llog -landroid
LOCAL_SRC_FILES := OpusEncoder.c OpusDecoder.c
include $(BUILD_SHARED_LIBRARY)
Other than the cosmetic change to the prebuilt library module, and restructuring my main Android.mk file, I didn't have to change a thing (you don't need to specify the LIB_PATH as I originally tried).

How to link .so file in android

I have two projects. The output of first one is libtest.so file. Using this shared object file in the 2nd project, i want to generate final android executable, AndroidExe.
I generated libtest.so and its Android.mk is given below
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS := -g
LOCAL_ARM_MODE := arm
LOCAL_MODULE :=test
LOCAL_SRC_FILES := test.c
export LD_LIBRARY_PATH=/data/local/tmp
include $(BUILD_SHARED_LIBRARY)
Here the problem i am facing is that, i don't know how to link this .so file in my final executable project. In this final project, i am using one of the function (sum(a,b)) defined in the .so lib.While do build, showing error undefined reference to 'sum'.Its Android.mk file is given below:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS := -g
LOCAL_ARM_MODE := arm
LOCAL_MODULE :=AndroidExe
LOCAL_SHARED_LIBRARIES := libtest.so
LOCAL_SRC_FILES := AndroidExe.c
include $(BUILD_EXECUTABLE)
just check ndk documentation and try some of the samples.

Include shared dynamic library in jni ndk build

I am trying to compile a ndk module for my android app with a Shared Library provided with these drivers:
http://www.extendo-printer.de/fileadmin/user_upload/extendo/Drivers/X-56-Hengstler-Extendo-LinuxDrivers-S684018-R2-V1_01-FINAL-2009JUL15.zip
I can compile fine with the defaults (using Hello JNI example). But when I add my code the my C file which references a .so library I need to work with I get compile errors stating it can not find the methods defined in the library. When I try to include it in Android.mk in LOCAL_SRC_FILES i get warnings when it builds (unsupported file extension) but it builds, but than my native method call fails (java.lang linkage error). Is there a proper way to include a .so and than reference it's functions in your native C code?
current Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := x56-jni
LOCAL_LDLIBS := libExoApi.so
LOCAL_SRC_FILES := x56-jni.c
include $(BUILD_SHARED_LIBRARY)
I tried with LOCAL_SHARED_LIBRARIES as well with same build error. I've also tried adding to LOCAL_SRC_FILES as stated above (LOCAL_SRC_FILES := x56-jni.c libExoApi.so) with a "," and as well as \ syntax.
Update
I've updated Android.mk to:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libExoApi
LOCAL_SRC_FILES := libExoApi.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := x56-jni
LOCAL_LDLIBS := libExoApi.so
LOCAL_SRC_FILES := x56-jni.c
LOCAL_SHARED_LIBRARIES := libExoApi
include $(BUILD_SHARED_LIBRARY)
This fails at:
[exec] Unable to recognise the format of the input file `/var/folders/_6/6jjydzjs457fnpsc9_5cgl980000gn/T//michael/usbserial-generated/libs/armeabi/libExoApi.so'

Categories

Resources