Problem:
A ca Library link fails to be debugged yesterday: ca vendors generally provide static ca libraries so that you can directly
Your Library link can be used together, but since apk compiler in ndk: android-ndk-r6b \ arm-linux-androideabi-4.4.3
The ca library uses the hisi compiler: The arm-eabi-4.4.0_hisi uses different compilation, so it needs to be in the linux android Environment
The ca static library is packaged into a dynamic library, and the ca function implemented by the user fails to be linked, and the generated dynamic library will be used in the ndk.
The following is a simple test example to illustrate how to compile and generate a dynamic library based on mutual dependencies.
1. compile and generate a dynamic library
First define the header file: test. h
1. <span style = "font-size: 16px;"> # ifndef XXX_TEST_H ___
2. # define XXX_TEST_H ___
3.
4./* implemented by the link Library */
5. extern void testA ();
6. extern void testB ();
7.
8./* implemented by the database and called externally */
9. extern void testC ();
10. extern void testD ();
11.
12. struct AAInterface {
13. void (* testA )();
14. void (* testB )();
15 .};
16.
17. extern void setInterface (struct AAInterface * cb );
18.
19. # endif/* XXX_TEST_H ___*/
20. </span>
Then the implementation file: testA. c
1. <span style = "font-size: 16px;" >#include <assert. h>
2. # include <stdlib. h>
3. # include <string. h>
4. # include <cutils/log. h>
5. # include "test. h"
6.
7. static struct AAInterface g_aa_interface;
8.
9./* implemented by the link Library */
10. extern void testA (){
11. g_aa_interface.testA ();
12 .}
13.
14. extern void testB (){
15. g_aa_interface.testB ();
16 .}
17.
18. extern void testCall (){
19. LOGI ("testCall 111 ");
20. testA ();
21. LOGI ("testCall 222 ");
22. testB ();
23. LOGI ("testCall 333 ");
24 .}
25.
26./* implemented by the database and called externally */
27. extern void testC (){
28. LOGI ("testC call in ---> ");
29. testCall ();
30. LOGI ("testC call out <---");
31 .}
32.
33. extern void testD (){
34. LOGI ("testD call in ---> ");
35. testCall ();
36. LOGI ("testD call out <---");
37 .}
38.
39. extern void setInterface (struct AAInterface * cb ){
40. LOGI ("setInterface call in --> ");
41. memset (void *) & g_aa_interface, 0x00, sizeof (g_aa_interface ));
42. g_aa_interface.testA = cb-> testA;
43. g_aa_interface.testB = cb-> testB;
44. LOGI ("setInterface call out <--");
45 .}
46. </span>
The most important thing here is to use the setInterface interface to solve the problem of mutual link, which is the essence. As you can see, this is also a dynamic
The best way to export a function from a database is to use QueryInterface and enumInterface.
Compilation Method:
LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
LOCAL_MODULE_PATH: = $ (TARGET_OUT_SHARED_LIBRARIES)
LOCAL_MODULE_TAGS: = eng
LOCAL_MODULE: = libtestASO
LOCAL_SRC_FILES: = \
TestA. c \
LOCAL_SHARED_LIBRARIES: = liblog \
LOCAL_C_INCLUDES + = \
$ (TOP)/frameworks/base/test/testA \
LOCAL_CFLAGS + =-D_cplusplus
LOCAL_PRELINK_MODULE: = false
Include $ (BUILD_SHARED_LIBRARY)
2. Use the generated dynamic library
1. <span style = "font-size: 16px;" >#include <assert. h>
2. # include <stdlib. h>
3. # include <string. h>
4. # include <cutils/log. h>
5. # include <test. h>
6.
7./* implemented by the link Library */
8. extern void testA (){
9. LOGI ("testA call ...");
10 .}
11.
12. extern void testB (){
13. LOGI ("testB call ...");
14 .}
15.
16. int main (void ){
17. struct AAInterface * itf = (struct AAInterface *) calloc (1, sizeof (struct AAInterface ));
18. itf-> testA = testA;
19. itf-> testB = testB;
20. setInterface (itf );
21. www.2cto.com
22. testC ();
23. testD ();
24. return 0;
25 .}
26. </span>
OK. I know how to solve this mutual dependency. The solution is equivalent to the solution .. For such A, link B is required, and B needs the relationship between link A, this method will play A very good role.
Author: andyhuabing