易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

sed 命令完全解析 之linux高级命令

sed 编辑指令的格式如下 :
sed option [address1[,address2]]function[argument] ***.c
位址参数 address1/2 为行数或匹配字串 , 表示所执行编辑的行 ;
函数参 数 function[argument] 为 sed 的内定函数 , 表示执行的编辑动作。
 
匹配字串:(reguler expression 字串)
& : 代表其前 pattern 字串
例:s ......

Linux fstab参数详解

1、fstab文件的作用
 使用权限 : 超级使用者
使用方式 : 使用编辑器来修改 /etc/fstab (eg. vi /etc/fstab)
说明 : 存放档案系统与目录结构对应资料的档案

件/etc/fstab存放的是系统中的文件系统信息。当正确的设置了该文件,则可以通过"mount/directoryname"命令来加载一个文件
系统,每种文件系 ......

linux 2.6源代码情景分析笔记之系统启动2

linux/arch/i386/boot/compressed/head.S
在setup()结束后,此函数就被移动到物理地址0x00100000处或者0x00001000处,这取决于内核映像是被高装载到ram中还是低装载到ram中。
解读函数:
startup_32:
        cld
        cli
  &n ......

Eclipse+QT4.6(Linux)

1、首先是QT4.6的安装,参见QT4.6+QT Creator1.3安装(Linux)
2、再参见Eclipse+Qt4配置步骤(Linux版)
  将QT4.6的路径,如:
/opt/qtsdk-2009.05/qt/bin/
3、OK!
4、可以同时使用Eclipse和QT Creator 两个IDE了,呵呵。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号