加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 教程 > 正文

Android - 动态库双向依赖解决技巧

发布时间:2021-11-23 14:27:25 所属栏目:教程 来源:互联网
导读:问题: 昨天调试一个CA库link失败的问题:ca厂商一般提供的都是静态ca库,这样子你直接将其与你的库link在一起即可使用,但由于apk在ndk中编译器:Android-ndk-r6barm-linux-androideabi-4.4.3 而ca库使用hisi编译器:arm-eabi-4.4.0_hisi 两者使用的编译不

问题:
 
昨天调试一个CA库link失败的问题:ca厂商一般提供的都是静态ca库,这样子你直接将其与你的库link在一起即可使用,但由于apk在ndk中编译器:Android-ndk-r6barm-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 <--");  
}  

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读