Android - 动态库双向依赖解决方法
Android - 动态库双向依赖解决方法
问题:
昨天调试一个CA库link失败的问题:ca厂商一般提供的都是静态ca库,这样子你直接将其与你的库link在一起即可使用,但由于apk在ndk中编译器:Android-ndk-r6b\arm-linux-androideabi-4.4.3
而ca库使用hisi编译器:arm-eabi-4.4.0_hisi 两者使用的编译不同,所以需要在linux android环境下将ca静态库打包成动态库,而且用户实现的ca函数将会link失败,生成的动态库将在ndk中使用。
下面是一个简单的测试例子,用于说明一下如何做到相互依赖而编译生成动态库的方法
1、首先编译生成动态库
首先定义头文件:test.h
- #ifndef XXX_TEST_H___
- #define XXX_TEST_H___
- /* 由link的库实现 */
- extern void testA();
- extern void testB();
- /* 由本身库实现而由外部调用 */
- extern void testC();
- extern void testD();
- struct AAInterface{
- void (*testA)();
- void (*testB)();
- };
- extern void setInterface(struct AAInterface *cb);
- #endif /* XXX_TEST_H___ */
然后实现文件:testA.c
- #include <assert.h>
- #include <stdlib.h>
- #include <string.h>
- #include <cutils/log.h>
- #include "test.h"
- static struct AAInterface g_aa_interface ;
- /* 由link的库实现 */
- extern void testA(){
- g_aa_interface.testA();
- }
- extern void testB(){
- g_aa_interface.testB();
- }
- extern void testCall(){
- LOGI("testCall 111");
- testA();
- LOGI("testCall 222");
- testB();
- LOGI("testCall 333");
- }
- /* 由本身库实现而由外部调用 */
- extern void testC(){
- LOGI("testC call in--->");
- testCall();
- LOGI("testC call out<---");
- }
- extern void testD(){
- LOGI("testD call in--->");
- testCall();
- LOGI("testD call out<---");
- }
- extern void setInterface(struct AAInterface *cb){
- LOGI("setInterface call in -->");
- memset((void*)&g_aa_interface,0x00,sizeof(g_aa_interface));
- g_aa_interface.testA = cb->testA;
- g_aa_interface.testB = cb->testB;
- LOGI("setInterface call out <--");
- }
|
评论暂时关闭