首页 > 技术文章 > linux 编译静态库及动态库例子--from周立功文档

dlutccj 2018-12-08 22:46 原文

/* hello1.c */
#include <stdio.h>
int hello1 (void)
{
printf("hello 1!\n");
return 0;
}
/* hello2.c */
#include <stdio.h>
int hello2 (void)
{
printf("hello 2!\n");
return 0;
}

vmuser@Linux-host:libhelloa$ gcc -c hello1.c hello2.c
生成2个.o文件

vmuser@Linux-host:libhellloa$ ar -r libhello.a hello1.o hello2.o
ar: creating libhello.a
生成libhello.a

调用如下

/* hello.c */

#include <stdio.h>
int hello2 (void)
{
  hello1();

       hello2();

gcc hello.c libhello.a

 

推荐阅读