linux下动态库与静态库
体验一下linux下编写和使用动态库与静态库,范例:helloworld程序。
首先编写静态库:
hellos.h
#ifndef _HELLO_S_H
#define _HELLO_S_H
void prints(char *str);
#endif
hellos.c
#include "hellos.h"
#include <stdio.h>
void prints(char *str)
{
printf("print in static way:%s",str);
}
开始编译成静态库:
gcc -c -o hellos.o hellos.c
ar cqs libhellos.a hellos.o
main.c
#include "hellos.h"
int main(void)
{
char *text = "hello,world\n";
prints(text);
}
使用静态库编译:gcc -o hello main.c -static -L. -lhellos
然后运行hello,输出:
print in static way: Hello World!
删除
libhellos.a和
hellos.*后, 程序仍然正常运行。
编写动态库
:
hellod.h
#ifndef _HELLO_D_H
#define _HELLO_D_H
void printd(char *str);
#endif
hellod.c
#include "hellod.h"
#include <stdio.h>
void printd(char *str)
{
printf("print in dynamic way:%s",str);
}
编译生成动态库:gcc -shared -o libhellod.so hellod.c
这样,libhellod.so就是生成的动态库。
export LD_LIBRARY_PATH=/root/program/link/dynamic/:$LD_LIBRARY_PATH,指定库文件路径。
如果系统装了SELINUX的话,要执行chcon -t textrel_shlib_t /root/program/link/dynamic/libhellod.so改变权限。
main.c
#include "hellod.h"
int main(void)
{
char *text = "hello,world\n";
printd(text);
}
gcc -o hello main.c -L./ -lhellod
然后运行hello可以看到输出
print in dynamic way: Hello World!
如果删除库文件,会出现:./hello: error while loading shared libraries: libhellod.so: cannot open shared object file: No such file or directory
相关文档:
1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI) 就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......
一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......
1、fstab文件的作用
使用权限 : 超级使用者
使用方式 : 使用编辑器来修改 /etc/fstab (eg. vi /etc/fstab)
说明 : 存放档案系统与目录结构对应资料的档案
文
件/etc/fstab存放的是系统中的文件系统信息。当正确的设置了该文件,则可以通过"mount/directoryname"命令来加载一个文件
系统,每种文件系 ......
前面利用开发板带的现成的东西step by step让Linux 2.4.19在开发板上跑起来了,对于开发的流程也有了一定的认识。现在想对每一步进行详细深入的探讨,好好学习一下,把笔记记录下来,省得忘记了。有些内容是从看过的书中摘要过来的,大部分是自己实践后的心得。我想记得详细点,也好为后面总结打好基础。
------- ......
1、首先从http://qt.nokia.com/downloads 下载“Qt SDK for Linux”,包括了QT4.6和QT Creator1.3。 Download Qt SDK for Linux/X11 32-bit** (353 MB)
2、修改文件qt-sdk-linux-x86-opensource-2009.05.bin的属性,让其可执行:
chmod u+x qt-sdk-linux-x86-opensource-2009.05.bin
3、双击qt-sdk-linux- ......