a third-party so existing file (for example: libXXX.so), a detailed interface documentation, you can directly call android, but now need to re-encapsulation layer in C, C calling third parties to write their own libXXX . so, and then compiled into their own so files, android in so files and then call your own.
question:
1.C how to call libXXX.so?
2.Android.mk document how to write?
detailed code invitations, thank you!
------ Solution ------------------------------------ --------
all Android.mk on top of the code, C code with Andrews Andrews does not matter, it is the basic C programming
------ Solution ---- ----------------------------------------
a detailed code do? Best Android.mk with C calling have.
with C calling party so
void * handle; int (* call_method) (void);
handle = dlopen (so_path, RTLD_LAZY);
/ / Function pointer
call_method = dlsym (handle, "method_name (function name called method)");
------ Solution --------- -----------------------------------
this trouble? Detailed interface documentation, you can directly call android
lib should have provided the header files it directly in android.mk inside the header files and lib join in.
Then in your own code # include the header file directly call the appropriate interface on it.
If you do not have to use dlopen dlsym header file
however. so you can directly copy files to / libs / armeabi / below
The code then use absolute paths dlopen ("/ data / data / lib / libxxx.so)
------ Solution ------------- -------------------------------
reference examples:
Android.mk:
LOCAL_PATH: = $ (call my-dir)
include $ (CLEAR_VARS)
LOCAL_MODULE: = hello-world
LOCAL_SRC_FILES: = hello-world.c
LOCAL_SHARED_LIBRARIES: = hello-jni
LOCAL_LDLIBS + =-llog
include $ (BUILD_SHARED_LIBRARY)
corresponding c code:
# include "string.h"
# include "jni.h"
# include "dlfcn.h"
# include
void * filehandle = NULL;
jint (* getResult) (JNIEnv *, jobject, jint, jint) = NULL;
jint JNICALL Java_com_example_hellojni_HelloAct_getInt (JNIEnv * env,
jobject thiz) {
jint result = 0;
filehandle = dlopen ("libhello-jni.so", RTLD_LAZY);
if (filehandle) {
getResult = (jint (*) (JNIEnv *, jobject, jint, jint)) dlsym (filehandle,
"Java_com_example_hellojni_HelloJni_add");
if (getResult)
result = getResult (env, thiz, 3, 10);
dlclose (filehandle);
filehandle = NULL;
}
return result + 1;
}
------ For reference only --------------------------------- ------
1. I remember it should be dlopen
2.LOCAL_SHARED_LIBRARIES added dynamic library references
purposes only ....
------ For reference only ---------------------------------------
I saw the inside of hal layer is obtained by dlopen to open dynamic library
------ For reference only ------------------------------ ---------
LOCAL_PATH: = $ (call my-dir)
# # XXX
#
include $ (CLEAR_VARS)
LOCAL_MODULE: = XXX
LOCAL_SRC_FILES: = XXX.c
LOCAL_CFLAGS: = -Iyour_lib_name/include
LOCAL_LDFLAGS + = -Lyour_lib_name/lib
LOCAL_LDLIBS: =-lyour_lib_name
include $ (BUILD_SHARED_LIBRARY)
------ For reference only ---------------------------------- -----
a detailed code do? Best Android.mk with C calling have.
------ For reference only -------------------------------------- -
This is very true. . . Oh
------ For reference only ------------------------------------- -
that so that you do not know to write their own thing api not tune it
------ For reference only ---------------- -----------------------
a detailed code do? Best Android.mk with C calling have.
with C calling party so
void * handle; int (* call_method) (void);
handle = dlopen (so_path, RTLD_LAZY);
/ / Function pointer
call_method = dlsym (handle, "method_name (function name called method)");
Thank you! I try.
------ For reference only -------------------------------------- -
C can call in C + +. so?
------ For reference only -------------------------------------- -
C calls so the file will not
But Android.mk file
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH: = $ (call my-dir)
include $ (CLEAR_VARS)
LOCAL_MODULE: = gpio --- "own name to define the so
LOCAL_SRC_FILES: = gpio.c --- "your C file names
LOCAL_LDLIBS: =-llog
include $ (BUILD_SHARED_LIBRARY)
没有评论:
发表评论