Linux动态链接库的建立
来源:互联网 发布:矩阵实际应用问题 编辑:程序博客网 时间:2024/06/11 23:50
hello.c
1#include "hello.h"
2 void hello()
3 {
4 printf("hello\n");
5 }
hello.h
1 #ifndef HELLO
2 #define HELLO
3 #include <stdio.h>
4 void hello();
5 #endif
test.c
1 #include "hello.h"
2 int main()
3 {
4 hello();
5 return 0;
6 }
1.创建动态链接库文件并编译
gcc -shared hello.c -o libhello.so
$gcc test.c
/tmp/cc8LkErr.o: In function `main':test.c:(.text+0x12): undefined reference to `hello'collect2: ld \u8fd4\u56de 1
不能找到函数hello3添加链接库后编译
gcc test.c -lhello -L.
4.运行a.out$ ./a.out ./a.out: error while loading shared libraries: libhello.so: cannot open shared object file: No such file or directory
不能找到链接库libhello.so5检测4的错误原因
$ ldd a.out linux-gate.so.1 => (0x00110000)libhello.so => not foundlibc.so.6 => /lib/libc.so.6 (0x00879000)/lib/ld-linux.so.2 (0x00859000)
提示libhello.so这个库文件没有找到6.添加环境变量
$ export LD_LIBRARY_PATH=/mnt:$LD_LIBRARY_PATH./a.outhello7.现在检查$ ldd a.out linux-gate.so.1 => (0x00110000)libhello.so => /mnt/libhello.so (0x00111000)libc.so.6 => /lib/libc.so.6 (0x00879000)/lib/ld-linux.so.2 (0x00859000)
一切OK了添加环境变量的方式有很多种
比如 /etc/ld.so.conf
~目下的.bash_profile都可以
- Linux动态链接库的建立
- Linux动态链接库的建立与使用
- 动态链接库的建立与测试
- Qt关于动态链接库的建立
- 建立动态链接库DLL
- C++建立动态链接库
- linux的动态链接库
- 如何建立及链接动态链接库。
- Delphi中动态链接库(DLL)的建立和使用
- 简单dll动态链接库的建立和应用
- Delphi中动态链接库(DLL)的建立和使用
- Delphi中动态链接库(DLL)的建立和使用
- Visual C++动态链接库的建立和调用
- Delphi中动态链接库(DLL)的建立和使用
- Delphi中动态链接库(DLL)的建立和使用
- Delphi中动态链接库(DLL)的建立和使用
- Delphi中动态链接库(DLL)的建立和使用
- vs中建立动态链接库的步骤
- 日期对称程序
- nls文件
- JDBC完全总结
- SQL*Loader的使用
- Eclipse启动错误 jvm terminated.Exit code=-1
- Linux动态链接库的建立
- 多线程知识点整理(多线程小结及解决应用挂死的问题)
- js打印
- js表格字段排序
- 获取属性文件properties
- 在Windows Azure上为iOS、 Android 和 Windows Phone构建可扩展的移动应用程序
- 如何估算oracle内存(SGA篇)
- 关于Android 下的自动化测试 (转载)
- SQL将存储过程的结果插入到临时表