[An Introduction to GCC 学习笔记] 08 链接外部外部动态库、C标准

Shared vs Static Libraries

  • External libraries are usually provide in two forms: static libraries and shared libraries.
    • 1 Static libraries are the ‘.a’ files. When a program is linked against a static library, the machine code from the object files for any external functions used by the program is copied from the library into the final executable.
    • 2 Shared libraries are handled with a more advanced form of linking, which makes the executable file smaller. They use the extension ‘.so’, which stands for shared object.

Shared Libraries

  • An executable file linked against a shared library contains only a small table of the functions it requires, instead of the complete machine code from the object files for the external functions.
  • Before the executable file starts running, the machine code for the external functions is copied into memory from the shared libray on disk by the operating system ~ a process referred to as dynamic linking.
  • Dynamic linking makes executable files smaller and saves disk space, because one copy of a library can be shared between multiple programs.
  • Most operating systems also provide a virtual memory mechanism which allows one copy of a shared library in physical memory to be used by all running programs, saving memory as well as disk space.
  • Furthermore, shared libraries make it possible to update a library without recompiling the programs which use it, provided the interface to the library does not change.
  • Because of these advantages, gcc compilers programs to use share libraries by default on most systems, if they are available.
  • When the executable file is started, its loader function must find the shared library in order to load it into memory. The default search path is predefined set of system directories such as ‘/usr/local/lib’ and ‘/usr/lib’.
  • The enrivonmental variable LD_LIBRARY_PASH can be set as the search directories list.

C Language Standards

  • By default, gcc compilers programs using the GNU dialect of the C language, referred to as GNU C.
  • The dialect incorporates the official ANSI/ISO standard for the C language with several useful GNU extensions, such as nested functions and variable-size arrays.
  • Most ANSI/ISO programs will compile under GNU C without changes.
  • There are several options which control the dialect of C used by gcc. The most commonly-used options are ‘-ansi’ and ‘-pedantic’. The specific dialects of the C language for each standard can also be selected with the ‘-std’ option.

Selecting Specific Standard

  • The specific language standard used by GCC can be controlled with the ‘-std’ option. The following C language standards are supported:
    • ‘-std=c89’ or ‘-std=iso9899:1990’ ~The original ANSI/ISO C language standard(ANSI X3. 159-1989, ISO/IEC 9899:1990). GCC incorporate the corrections in the two ISO Technical Corrigenda to the original standard.
    • ‘-std=iso9899:199409’ ~ The ISO C language standard with ISO Amendment 1, published in 1994. This amendent was mainly concerned with internationalization, such as adding support for multibyte characters to the C library.
    • ‘-std=c99’ or ‘-std=iso9899:1999’ ~ This revised ISO C language standard, published in 1999 (ISO/IEC 9899:1999)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值