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


相关文档:

在vMware装上linux鼠标无法使用问题解答


在vMware装上linux鼠标无法使用问题解答
     昨天装了Linux+VMware,还用得好好的,今天鼠标就不能用,现在终于把问题解决了!
       目前大部分鼠标是usb接口的,特别是笔记本。在vMware装上linux时鼠标类型选择带滑轮的USB后,进入系统时将出现鼠标无法使用的情 ......

VMware下windows和Linux共享文件的方法

                                                  VMwar ......

linux压缩命令

01-.tar格式
解包:[*******]$ tar xvf FileName.tar
打包:[*******]$ tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)
02-.gz格式
解压1:[*******]$ gunzip FileName.gz
解压2:[*******]$ gzip -d FileName.gz
压 缩:[*******]$ gzip FileName
03-.tar.gz格式 ......

Linux(Ubuntu) 中的乱码解决大全(待续)

   由于Linux不是中国人开发的,开发过程中也不是以中文为母语,虽有中文语言包,在软件兼容性上出现中文乱码也在所难免。我抽取网络上前人的经验,结合自己的理解,将他们加以总结,希望对后来者有所帮助。
     1、html文件乱码;
        &nbs ......

linux 2.6源代码情景分析笔记之进程2


能被独立调度的每个执行上下文都必须拥有自己的进程描述符。进程和进程描述符之间有严格的对应关系,使用32位进程描述符地址标识,进程描述符指针指向这些地址,内核对进程的大部分引用是通过进程描述符指针进行的。
可以使用pid(进程标识符)来标记进程,存放在字段pid中,PID被顺序编号,新创建的进程PID通常是前一个 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号