About Store Forum Documentation Contact



Post Reply 
[Android] i can't use my lib
Author Message
take_de_x Offline
Member

Post: #1
[Android] i can't use my lib
Hi. my name is take.de.x grin

I maked my C++ library, libtest.a, iimplemented global function
I was going to link this library to Esenthel Application
Then it became such an error.

----------------------------------------
D:/(ndk directory)/toolchains/x86-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.6/../../../../i686-linux-android/bin/ld.exe: ./obj/local/x86/objs-debug/Project/Main.o: in function Init():jni/../../Source/main.cpp:21: error: undefined reference to 'GlobalFunction(void*, unsigned int*)'
D:/(ndk directory)/toolchains/x86-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.6/../../../../i686-linux-android/bin/ld.exe: ./obj/local/x86/objs-debug/Project/Main.o: in function Init():jni/../../Source/main.cpp:23: error: undefined reference to 'inc::misc::NamedFunction(void*, int, unsigned int)'
----------------------------------------

I seem to succeed in a link in armeabi.

please help me.

-------------------------------------
OS:Windows7
----- global_function.h ---------------
#ifndef _TEST_MISC_GLOBAL_FUNCTIONS_H_
#define _TEST_MISC_GLOBAL_FUNCTIONS_H_

void GlobalFunction(void* ptr, size_t* size);

namespace inc {
namespace misc {
void NamedFunction(void*ptr, int count, size_t size);
}
}
#endif // _TEST_MISC_GLOBAL_FUNCTIONS_H_

----- global_function.cpp ---------------
#include <test/misc/global_functions.h>

void GlobalFunction(void* ptr, size_t* size)
{
int a = 0;
++a;
}

namespace inc {
namespace misc {
void NamedFunction(void* ptr, int count, size_t size)
{
int a = 0;
++a;
}

}
}
----- Android.mk ---------------
LOCAL_PATH := $(call my-dir)

MY_INCLUDES := $(LOCAL_PATH)/../../include \
$(LOCAL_PATH)/../src
# test
include $(CLEAR_VARS)

LOCAL_MODULE := test
LOCAL_CFLAGS := -ffast-math -fsigned-char -O2 -fPIC -DPIC \
-DBYTE_ORDER=LITTLE_ENDIAN -D_ARM_ASSEM_
TARGET_ARCH_ABI := armeabi armeabi-v7a x86

LOCAL_C_INCLUDES := $(MY_INCLUDES)

CPP_FILES := $(shell find $(LOCAL_PATH)/../src -name '*.cpp' | grep -v precompile)
C_FILES := $(shell find $(LOCAL_PATH)/../src -name '*.c' | grep -v precompile)
LOCAL_SRC_FILES := $(CPP_FILES)
LOCAL_SRC_FILES += $(C_FILES)

include $(BUILD_STATIC_LIBRARY)

----- Android.mk(Esenthel Application) ---------------
LOCAL_PATH := $(call my-dir)

# EsenthelEngine
include $(CLEAR_VARS)
LOCAL_MODULE := EsenthelEngine
LOCAL_SRC_FILES := (Essenthel Directory)/Bin/Android/EsenthelEngine-$(TARGET_ARCH_ABI).a
include $(PREBUILT_STATIC_LIBRARY)

# libtest
include $(CLEAR_VARS)
LOCAL_MODULE := libtest
LOCAL_SRC_FILES := D:/(My library Directory)/obj/local/armeabi/libtest.a
include $(PREBUILT_STATIC_LIBRARY)

# Project
include $(CLEAR_VARS)
LOCAL_MODULE := Project
LOCAL_SRC_FILES := Main.cpp
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 -lz -lOpenSLES
LOCAL_STATIC_LIBRARIES := EsenthelEngine android_native_app_glue cpufeatures libtest
LOCAL_CFLAGS := -I.. -ID:/(My library Directory)/include -fshort-wchar -ffast-math -Wl,--no-wchar-size-warning -fpermissive
LOCAL_CPPFLAGS := -I.. -ID:/(My library Directory)/include -fshort-wchar -ffast-math -Wl,--no-wchar-size-warning -fpermissive -ffriend-injection -Wno-invalid-offsetof -std=c++11
LOCAL_CPP_FEATURES := rtti exceptions
include $(BUILD_SHARED_LIBRARY)

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


---------------------------------------------------------------------------
(This post was last modified: 05-28-2014 03:12 PM by take_de_x.)
05-28-2014 03:04 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: [Android] i can't use my lib
If this will help you with anything:
EE operates on 3 architectures for Android - armeabi armeabi-v7a x86
If you want to use a custom library you need to supply it for these archs too.
Compile it for those platforms, and then try to use it like:
D:/(My library Directory)/obj/local/armeabi/libtest-$(TARGET_ARCH_ABI).a
instead of
D:/(My library Directory)/obj/local/armeabi/libtest.a
05-28-2014 11:04 PM
Find all posts by this user Quote this message in a reply
take_de_x Offline
Member

Post: #3
RE: [Android] i can't use my lib
Hi. Esenthel

It succeeded as follows.
Thank you for helping.

------------------------------------
call ndk-build.cmd APP_ABI=armeabi
call ndk-build.cmd APP_ABI=armeabi-v7a
call ndk-build.cmd APP_ABI=x86
------------------------------------

These files were made.

------------------------------------
obj\local\armeabi\libtest.a
obj\local\armeabi-v7a\libtest.a
obj\local\x86\libtest.a
------------------------------------

It renamed as follows.

------------------------------------
mkdir lib
copy /Y obj\local\armeabi\libtest.a lib\libtest-armeabi.a
copy /Y obj\local\armeabi-v7a\libtest.a lib\libtest-armeabi-v7a.a
copy /Y obj\local\x86\libtest.a lib\libtest-x86.a
------------------------------------

In Include Libraries of EsenthelEngine, it set up as follows.

------------------------------------
D:\(My Library Directory)\lib\libtest-$(TARGET_ARCH_ABI).a
------------------------------------

Thank you very much.
05-29-2014 12:25 AM
Find all posts by this user Quote this message in a reply
Post Reply