eclipse 加载现有的.so文件
2016-02-23 17:17
281 查看
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文件如上面所示。
下面就是加载刚刚我们生成的.so文件。
右键工程,在属性中选择c/c++ Build 下的Setting 右边的库链接,上面的Libraries(-l)选择的是库的名字,我们这里的库名为test ,下面的Librarv search path(-L)选择的是动态库所在路径。
#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文件如上面所示。
下面就是加载刚刚我们生成的.so文件。
右键工程,在属性中选择c/c++ Build 下的Setting 右边的库链接,上面的Libraries(-l)选择的是库的名字,我们这里的库名为test ,下面的Librarv search path(-L)选择的是动态库所在路径。
相关文章推荐
- Java注解
- Java Reflection(一):Java反射指南
- POPTEST老李分享DOM解析XML之java
- Java静态绑定和动态绑定
- POPTEST老李谈JVM、JRE、JDK、java ee sdk with jdk区别
- java项目映射到外网
- eclipse 快捷键Alt+/ 不能补充syso
- Spring依赖注入(DI)
- spring多数据源的处理 mybatis实现跨库查询
- 【第三章】 DI 之 3.1 DI的配置使用 ——跟我学spring3
- 页面工具说明书
- SPRING4学习日志1
- java 字符串替换函数replaceAll 一次同时替换多个字符串
- java 多线程
- 定制化Azure站点Java运行环境(2)
- 关于RxJava的学习(1)
- 定制化Azure站点Java运行环境(1)
- java中线程同步
- SpringMVC Ehcache的缓存实现
- 快速上手Spring--7. ref的用法