交叉编译环境下静态库的制作与测试

1、编写my_print.c源文件,内容如下:

#include <stdio.h>

void cout(const char * message)
{
    fprintf(stdout, "%s\n", message);
}

2、编写my_lib.h头文件,内容如下:
 

#ifndef __MY_LIB_H__
#define __MY_LIB_H__

void cout(const char *);

#endif

3、编写test_static_lib.c源文件,内容如下:
 

#include <stdio.h>
#include "my_lib.h"


int main(int argc, char *argv[])
{
    cout("This is a static lib test!\n");

    return 0;
}

4、编译my_print.c源文件:
arm-hisiv500-linux-gcc -c my_print.c

      

5、归档目标文件,得到静态库。

arm-hisiv500-linux-ar crv libmylib.a my_print.o

6、生成ELF文件:
arm-hisiv500-linux-gcc test_static_lib.c  -L. -lmylib -o test_static_lib

7、将ELF文件拷贝至开发板,执行

 

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值