//test_so.h
#include <stdio.h>
void test_a();
void test_b();
//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
#include "so_test.h"
int main()
{
test_a();
test_b();
return 0;
}
编译步骤
gcc test_a.c test_b.c -fPIC -shared -o libtest.so
gcc test.c -L. -ltest -o test
./test
解决链接库问题:
#vim /etc/profile
LD_LIBRARY_PATH=/mnt/hgfs/Ubuntu_shared/so:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
# source /etc/profile
本文介绍了一个简单的共享库libtest.so的创建过程及其使用方法。通过gcc命令进行编译并链接共享库,实现了两个函数test_a()和test_b()的功能调用。文章还展示了如何设置LD_LIBRARY_PATH环境变量来解决链接库问题。

被折叠的 条评论
为什么被折叠?



