test_a.c 文件
#include "so_test.h"
void test_a(){
printf("this is in test_a..\n");
}
test_b.c 文件
#include "so_test.h"
void test_b(){
printf("this is in test_b..\n");
}
test_c.c 文件
#include "so_test.h"
void test_c(){
printf("this is in test_c..\n");
}
so_test.h文件
#include "stdio.h"
#ifndef SO_TEST_H_
#define SO_TEST_H_
void test_a();
void test_b();
void test_c();
#endif /* so_test_H_*/
将这几个文件编译成一个动态库:libtest.so
$ gcc test_a.c test_b.c test_c.c -fPIC -shared -o libtest.so
我们在eclipse中新建一个C工程文件,
#include "so_test.h"
int main()
{
test_a();
test_b();
test_c();
return 0;
}
再在工程src目录下新建一个so_test.h文件如上面所示。
右键工程,在属性中选择c/c++ Build 下的Setting 右边的库链接,上面的Libraries(-l)选择的是库的名字,我们这里的库名为test ,下面的Librarv search path(-L)选择的是动态库所在路径。