While static libraries are useful and essential tools, they are also a source of confusion to programmers because of the way the Unix linker uses them to resolve external references.During the symbol resolution phase, the linker scans the relocatable object files and archives left to right in the same requential order that they appear on the complier driver's command line.(The driver automatically translates any .c files on the command line into .o files) During this scan, the linker maintains a set E of relocatable object files that will be merged to form the executable, a set U of unresolved symbols (i.e., symbols referred to , but not yet defined), and a set D of unresolved symbols (i.e., symbols referred to , but not ye defined), and a set D of symbols that have been defined in previous input files. Initially, E, U, and D are empty.

For each input file f on the command line, the linker determines if f is an object file or an archive. If f is an object file, the linker add f to E, updates U and D to reflect the symbol definitions and referrences in f, and proceeds to the next input file.

if f is an archive, the linker attempts to match the unresolved symbols in U against the symbols defined by the members of the archive. If some archive member, m, defines a symbol that resolves a reference in U, then m is added to E, and the linker updates U and D to reflect the symbol definitions and referencces in m. This process iterates over the member object files in the archive until a fixed point is reached where U and D no longer change. At this point, any member object files not contained in E are simply discarded and the linker proceeds to the next input file.

if U is nonempty when the linker finishes scanning the input files on the command line, it prints an error and terminates . Otherwise, it merges and relocates the object files in E to build the output executable file.

Unfortunately, this algorithm can result in some baffling link-time errors because the ordering of libraries and object files on the command line is significant. If the library that defines a symbol appears on the command line before the object file that references that symbol, then the reference will not be resolved and linking will fail.

「操作系统」:Linker Use static Libraries的更多相关文章

  1. 「操作系统」: Conditional Move Instructions(trap)

    Not all conditional expressions can be compiled using conditional moves. Most significantly, the abs ...

  2. 「操作系统」:The most useful condition codes

    CF: Carry Flag.The most recent operation generated a carry out of the most significant bit. Used to ...

  3. 「MoreThanJava」计算机系统概述

    「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...

  4. 2019 年在 Raspberry Pi 「树莓派」上运行的 10 个操作系统推荐

    原文:2019 年在 Raspberry Pi 「树莓派」上运行的 10 个操作系统推荐 image Raspberry Pi** 是一款基于 ARM 的单板计算机,默认运行一款称为 Raspbian ...

  5. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  6. 「2014-3-18」multi-pattern string match using aho-corasick

    我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...

  7. 「MoreThanJava」Java发展史及起航新世界

    「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...

  8. 「MoreThanJava」Day 4:面向对象基础

    「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...

  9. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

随机推荐

  1. 委托与Lambda表达式

    ~,先不急说委托和Lambda表达式,先看两个例子再说: 1. 通过委托,为一个数字加10,如下代码: class Program { private delegate int JiSuan(int ...

  2. 【转】Linq实现DataTable行列转换

    出处:http://www.cnblogs.com/li-peng/ 转换前的table: 转换后的table: 代码里有详细的说明, 还有一些参数我都截图了下面有 using System;usin ...

  3. 【Tomcat】使用Eclipse发布项目时,项目启动路径错误。

    这种情况下,,通常会去C:\User\[USERNAME]\或者Tomcat路径下面的一个temp文件夹里面找项目文件,由此出现报错. 这时候解决方法为: 双击Eclipse的Servers里面的to ...

  4. 简单天气应用开发——API接口

    寒假回家无事,想到自学iOS开发已有一段时间,还没做过真正自己的应用,就起了做一个天气预报App的念头. 想到就做.天气预报第一步自然是找到好用的API接口来获取天气信息.在百度上搜索了一圈,找到的都 ...

  5. Spring—Hibernate

    1.家jar包 2配置applicationContext与xxx.hbm.xml(根据需要决定是否配置hibernate.hbm.xml) applicationContext.xml <?x ...

  6. java源码解析——Stack类

    在java中,Stack类继承了Vector类.Vector类和我们经常使用的ArrayList是类似的,底层也是使用了数组来实现,只不过Vector是线程安全的.因此可以知道Stack也是线程安全的 ...

  7. Python的MySQLdb模块安装,连接,操作,增删改

    1. 首先确认python的版本为2.3.4以上,如果不是需要升级python的版本     python -V   检查python版本 2. 安装mysql, 比如安装在/usr/local/my ...

  8. Win32 GDI基础(笔记)

    1.GDI名字的意义 GDI Graphic Device Interface,我说不清和GUI有什么区别.可能一种针对设备,一种针对用户而言吧,反正以后都说GDI,也就是Windows的图形编程. ...

  9. HDU 3571 N-dimensional Sphere

    高斯消元,今天数学死了无数次…… #include <cstdio> #include <cstring> #include <cmath> #include &l ...

  10. hdoj 1233 还是畅通工程(最小生成树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1233 思路分析:该问题为最小生成树问题,使用kruskal算法或者prim算法即可解决: 代码如下: ...