您的位置:首页 > 编程语言 > Java开发

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)选择的是动态库所在路径。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: