8种机械键盘轴体对比

本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?

This article mainly introduces the statics library and shared library on Linux and has done some experiments for better comprehension.

Static library,又称为归档文档(archive). 在Linux系统中一般以.a作为后缀名.用以声明除了C语言标准库之外的库文档的目录. 这个声明是静态的,也就是说,当许多应用进程同时运行并且都是用来自同一个函数库的函数时,在内存中就会存有这个函数的多份拷贝.这将大量消耗内存和磁盘空间. 类似与Windows中的静态链接库.lib文档

共享库(shared library / dynamic library)

共享库克服了静态库的不足,典型的后缀名是.so。类似与Windows下的dll文档。

In Arch Linux, the paths of shared library files are declared in /etc/ld.so.conf. You can add your specified path into this file and then using sudo ldconfig for generating their so-name files if there is update of these library files happening.

The naming suggestion of Linux shared library

Every shared library has its filename and so-name(Short for shared Object name, 简单共享名). The following naming rules are commonly obeyed:

filename: libname.so.x.y.z

so-name: libname.so.x

x 代表了主版本号,主版本号之间不同通常是无法相互兼容的。

y 代表次版本号,可以向下兼容。

z 代表发布版本号,之间可以相互兼容。

当运行 ldconfig 命令后,系统会为制定目录下面的动态库文档新建与 so-name 同名的软链接。当编译完进程需要链接的时候,查找的就是这些对应的 so-name。可以用环境变量 LD_LIBRARY_PATH 指定so-name files所在的目录。

First experiment

Supposing that we want to create a shared library for calling function hello declared by hello.h, we start by writing our code here:

1

2

3

4

5

6

7void (const char* name)

{

printf("hello %s!n", name);

}1

2void (const char* name);

Then we compile it by gcc to generate shared lib:

1gcc hello.c -fPIC -shared -Wl,-soname,libhello.so.0 -o libhello.so.0.0.1

Let me explain every option of the above command. -fPIC means generating position independent code, i.e., address jumping is relative rather than absolute. This option is required in generating library file because lib file usually locates at some place and is called by programs from other places, or the program is generated at some place but is moved to other path. -shared -o indicates a shared library file .so.x.y.z. And -Wl,-soname,libhello.so.0 specifies its so-name as ‘libhello.so.0’.

Now we check our files and should see a new file like this picture:

Next we update by ldconfig

1ldconfig -n shared-library/

Note that -n specifies the dir only being processed(Because we only created one lib file under shared-library, it has no need to update all). If you have added the path into /etc/ld.so.conf, you can also simply run sudo ldconfig and see the same change:

As we can see, the so-name symbolic link has been created. Now we can test this new lib by writing a test code:

1

2

3

4

5

6

7

8int main()

{

hello("handy");

return 0;

}

Then we create a symbolic link to the so-name file in order for gcc compiler specification:

Now we make these three stages of shared library prepared(.so, .so.x and .so.x.y.z), then we compile and link, with relevent paths specified:

1gcc main.c -I /home/shane/Experiments/shared-library/ -L. -lhello -o main

where -I specifies the path of hello.h, -L for the path of libhello.so.

Since we have specified the path of so-name to gcc compiler but have not done that for Linux executer(one of the features of shared library), an error of failing to find the so-name file appears when running the program. So we use LD_LIBRARY_PATH to set it and run again:

1export LD_LIBRARY_PATH="$HOME/Experiments/shared-library/"

More exploration

用ldd查看其依赖的动态库:

我们发现main进程依赖的动态库名字是libhello.so.0,既不是libhello.so也不是libhello.so.0.0.1。其实在生成main进程的过程有如下几步:链接器通过编译命令-L. -lhello在当前目录查找libhello.so文档

读取libhello.so链接指向的实际文档,这里是libhello.so.0.0.1

读取libhello.so.0.0.1中的SONAME,这里是libhello.so.0

将libhello.so.0记录到main进程的二进制数据里

所以你看,进程并不知道 so-name file 在哪里,我们当然要在运行进程前 specify 一波了。

Second experiment

Now we emulate the situation of updating lib files. Suppose that we modify our code:

1

2

3

4

5

6

7# include

void hello(const char* name)

{

printf("hello %s, welcome to the world!n", name);

}

Since the change is trivial, we keep the so-name when compiling:

1gcc hello.c -fPIC -shared -Wl,-soname,libhello.so.0 -o libhello.so.0.0.2

Now there are two versions exist, we update by ldconfig and see the change:

The so-name file link to the new version of lib file. And we run the program and see the immediate change:

So you see, this is the significance or the essence of so-name mechanism. We don’t have to re-link the program after modifying the shared library code.

Summary

In practical production, the compilation and execution are usually departed. Generally:specify the so-name when generating shared lib files

Ensure the availability of libXXX.so file by -L and -l when linking executable program

Ensure the existence of shared lib file and use LD_LIBRARY_PATH to specify the directory of its so-name link when running program

References

linux系统中 库分为静态库和,Linux系统静态库与共享库相关推荐

  1. 在linux系统中删除目录的命令是,在Linux中使用rmdir、rm和find命令删除目录的方法...

    本文介绍使用rmdir.rm和find命令在Linux操作系统中删除目录的方法.在Linux系统中有几种不同的方法可以删除目录,如果你使用桌面文件管理器(如Gnome的文件或KDE的Dolphin), ...

  2. win12服务器文件设置只读,如何在Win10系统中更改文件夹的只读或系统属性

    正常情况下通过右键属性只能更改文件的只读属性,系统win10属性则连相应选项都没有.那么如何在Win10系统中更改文件夹的只读或系统属性呢?下面跟着学习啦小编来一起了解下吧. 在Win10系统中更改文 ...

  3. linux常见系统目录,Linux系统中常见目录有哪些?linux运维学习中心

    Linux系统中常见目录有哪些?随着开源软件在世界范围内影响力日益增强,Linux服务器操作系统在整个服务器操作系统市场格局中占据了越来越多的市场份额,市场对于Linux运维人才的需求也是逐渐增加.L ...

  4. linux系统中的挂载有什么用,linux 挂载详解

    linux 挂载详解 发布时间:2009-06-10 00:16:54   作者:佚名   我要评论 linux是一个优秀的开放源码的操作系统,可以运行在大到巨型小到掌上型各类计算机系统上,随着lin ...

  5. linux系统中动态链接库的默认位置是,linux动态链接库的加载顺序

    一. Linux 动态库选择顺序指: 1.  编译程序时用到动态库,该从那些地方查找,按照怎么样的顺序查找? 2.  运行程序时需要动态库,该从那些地方查找,按照怎么样的顺序查找? 二.gcc 编译程 ...

  6. linux命令中选项分为,Linux 考试试题

    Linux 考试试题 一.选择题 (每小题2分,共50分) 1.在创建Linux分区时,一定要创建( D )两个分区 A. FAT/NTFS B. FAT/SWAP C. NTFS/SWAP D.SW ...

  7. linux系统中硬盘及分区如何命名,Linux硬盘命名和安装分区

    硬盘命名: 硬盘命名基于文件,一般有如下文件方式: /dev/hda1 /dev/sdb3 具体含义如下: /dev:是所有设备文件存放的目录. hd和sd:他们是区别的前两个字母,代表该分区所在的设 ...

  8. 在linux系统中查看组管理信息命令,Linux常用命令(五)账号和组管理

    Linux常用命令(五)账号和组管理 一.管理用户账号 1.用户账号的分类 ■超级用户:root用户是Linux系统中默认的超级用户账号,对本主机拥有最大的权限,类似于Windows          ...

  9. 在linux系统中进行路由探测,如何在Linux操作系统中运行Traceroute命令?

    Traceroute是Linux操作系统中的命令工具,可用于查看网络数据包的路由.Traceroute可以帮助确定网络数据包传输的质量好坏,同时对于排除缓慢的网络连接故障也很有用. 在租用 关于Tra ...

  10. linux cst时间转换,linux系统中CST与EDT时间转换以及系统时间与网络时间同步

    初始时间:2012年 09月 14日 星期五 18:15:33EDT [root@test ~]# mv /etc/localtime /etc/localtime.bak [root@test ~] ...

最新文章

  1. CString工作原理和常见问题分析
  2. SDUT_2118 数据结构实验之链表三:链表的逆置
  3. Jquery Mobile转场特效之slide | 小小iPhone开发
  4. android excel 筛选功能,Android实现Excel表格展示数据
  5. Java面试总结系列之Collections.sort()
  6. ArrayPool 源码解读之 byte[] 也能池化?
  7. php本地的调试安装,教你本地安装、运行、调试PHP程序
  8. 关于JS的传递方式的小理解
  9. 使用模板来解决接口继承问题
  10. 在XML文件中定义动画(1)
  11. Java教程:Java程序的运行过程(执行流程)分析
  12. UGUI的Drag实现鼠标拖拽
  13. DatabaseMetaData的用法(转)
  14. 新网站收录及备忘录网址
  15. ListView 优化之 ViewHolder 复用机制
  16. ios animation 动画效果实现
  17. 魏文王问扁鹊的注释_魏文王问扁鹊曰阅读答案与翻译
  18. 和数集团首款自研虚拟数字人上线,“始祖龙”带你跨山海,链未来
  19. puppeteer在linux上模拟浏览器截图——截取微信公众号文章全文实例
  20. 渲染函数render

热门文章

  1. 转发:Ajax动态画EChart图表
  2. Tcpdump抓包工具的使用
  3. 原生Js_实现广告弹窗
  4. 输出控制台信息到日志 并 通过cronolog对tomcat进行日志切分
  5. 关于字符串 --java
  6. WordPress分类列表函数:wp_list_categories用法及参数详解举例
  7. iOS 升级https的方案选择
  8. GCPC2014 C Bounty Hunter
  9. Android中ExpandableListView控件基本使用
  10. 浏览器是如何工作的系列:渲染引擎