欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android Q预编译静态库实例

程序员文章站 2022-03-27 21:49:09
如果厂商提供了一个静态库,如何编译进系统呢,可参考external/demo/Android.bpcc_prebuilt_library_static { name: "hub", compile_multilib: "both", multilib: { lib32: { srcs: ["hub.a"], }, lib64: { srcs: ["hub.a"],...

如果厂商提供了一个静态库,如何编译进系统呢,可参考

external/demo/Android.bp

cc_prebuilt_library_static {
    name: "hub",
    compile_multilib: "both",
    multilib: {
        lib32: {
            srcs: ["hub.a"],
        },
        lib64: {
            srcs: ["hub.a"],
        },
    },
}

cc_binary {
    name: "demo",
    srcs: ["demo.c"],
	static_libs: [
        "hub",
    ],
    cflags: [
	"-Werror",
	"-Wno-unused-parameter",
	"-Wno-unused-variable",
	],
}

external/demo/demo.c

#include <stdio.h>
extern int sub(int a,int b);
int main(int argc, char *argv[])
{
	printf("ret=%d\n",sub(100,0));
	return 0;
}

如何生成hub.a

external/demo/hub.c

int sub(int a,int b){
	return a-b;
}

 运行如下命令生成hub.a

./prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc external/demo/hub.c -o external/demo/hub.o -c
./prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-ar rcs external/demo/hub.a external/demo/hub.o

本文地址:https://blog.csdn.net/mike8825/article/details/108550282

相关标签: ANDROID