linux 编译静态库及动态库例子--from周立功文档

/* hello1.c */
#include <stdio.h>
int hello1 (void)
{
printf("hello 1! ");
return 0;
}
/* hello2.c */
#include <stdio.h>
int hello2 (void)
{
printf("hello 2! ");
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

原文地址:https://www.cnblogs.com/dlutccj/p/10089562.html