易截截图软件、单文件、免安装、纯绿色、仅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


相关文档:

LINUX期末复习 SHELL编程

一、SHELL简介 ①什么是SHELL 答:一个作为用户与LINUX系统之间的操作接口程序,允许用户向操作系统输入需要执行的命令。
      一种高级、解释性的程序语言。     ②SHELL的种类 ③SHELL的执行
         .  ......

Linux fstab参数详解

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

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

基于ATMEL AT91RM9200的嵌入式Linux移植笔记


  前面利用开发板带的现成的东西step by step让Linux 2.4.19在开发板上跑起来了,对于开发的流程也有了一定的认识。现在想对每一步进行详细深入的探讨,好好学习一下,把笔记记录下来,省得忘记了。有些内容是从看过的书中摘要过来的,大部分是自己实践后的心得。我想记得详细点,也好为后面总结打好基础。
------- ......

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号