linux下C语言编程动态库so的编写及调用

简介: <pre code_snippet_id="609956" snippet_file_name="blog_20150301_1_4475452" name="code" class="cpp">//test_so.h#include <stdio.h>void test_a();void test_b();//test_a.c#include "so_test.h"
//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


目录
相关文章
|
1月前
|
监控 网络协议 API
C语言系统编程
C语言系统编程
|
1月前
|
存储 Linux C语言
Linux系统下C语言的文件操作
Linux系统下C语言的文件操作
17 0
|
1天前
|
C语言
C 语言解 常见编程题(下)
C 语言解 常见编程题
15 0
|
21天前
|
小程序 Linux API
Linux用C语言模拟‘ls‘命令
Linux用C语言模拟‘ls‘命令
11 1
|
22天前
|
Linux 测试技术 C语言
【Linux】应用编程之C语言文件操作
【Linux】应用编程之C语言文件操作
|
1月前
|
缓存 算法 Linux
深入理解Linux动态库加载:路径、问题与解决方案
深入理解Linux动态库加载:路径、问题与解决方案
61 0
|
1月前
|
前端开发 Unix Linux
Linux indent命令 (格式化C语言源代码的程序)
Linux indent命令 (格式化C语言源代码的程序)
18 0
Linux indent命令 (格式化C语言源代码的程序)
|
1月前
|
Linux 编译器 vr&ar
【Linux】—— 详解动态库和静态库
【Linux】—— 详解动态库和静态库
|
1月前
|
自然语言处理 算法 搜索推荐
C语言的编程
C语言的编程
9 1
|
Linux
linux下so动态库一些不为人知的秘密(上)
linux 下有动态库和静态库,动态库以.so为扩展名,静态库以.a为扩展名。二者都使用广泛。本文主要讲动态库方面知识。        基本上每一个linux 程序都至少会有一个动态库,查看某个程序使用了那些动态库,使用ldd命令查看  # ldd /bin/ls linux-vdso.
1239 0