1. 当在同一个目录下静态库和共享库同名时,共享库优先
hello.h头文件
#ifndef HELLO_H
#define HELLO_H
void print_hello();
#endif
hello.c源文件
#include "hello.h"
#include <stdio.h>
int main(int argc,char *argv[])
{
printf("hello world!");
}
测试使用源文件main.c
#include "hello.h"
int main(int argc,char *argv[])
{
printf_hello();
}
1.1 编译静态库和共享库
[test@hadoop hello]$ ls
hello.c hello.h main.c
[test@hadoop hello]$ gcc -c hello.c
[test@hadoop hello]$ ar crs libhello.a hello.o
[test@hadoop hello]$ gcc -shared -fPIC -o libhello.so hello.o
[test@hadoop hello]$ ls
hello.c hello.h hello.o libhello.a libhello.so main.c