zoukankan      html  css  js  c++  java
  • Linux 动态链接库学习笔记

    参考资料:

    http://www.linuxidc.com/Linux/2012-01/50739.htm
    http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

    1.

    -fpic

    Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant addresses through a global offset table (GOT). The dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of GCC; it is part of the operating system). If the GOT size for the linked executable exceeds a machine-specific maximum size, you get an error message from the linker indicating that-fpicdoes not work; in that case, recompile with-fPICinstead. (These maximums are 8k on the SPARC and 32k on the m68k and RS/6000. The x86 has no such limit.)

    Position-independent code requires special support, and therefore works only on certain machines. For the x86, GCC supports PIC for System V but not for the Sun 386i. Code generated for the IBM RS/6000 is always position-independent.

    这是编译器选项

    2.

    -shared

    Produce a shared object which can then be linked with other objects to form an executable. Not all systems support this option. For predictable results, you must also specify the same set of options used for compilation (-fpic,-fPIC, or model suboptions) when you specify this linker option.

    这是链接器选项

    3.

    dlfcn.h (对应的.a文件是libdl.a, 因此你在链接的时候要加上 -ldl)

    这个头文件包含了 dlopen, dlsym, dlclose, dlerror 等等与动态链接库操作相关的函数

    类似于Windows 中的 LoadLibrary, GetProcAddress 等等

    4.

    Demo下载

  • 相关阅读:
    转 方法多态与Duck typing;C#之拙劣与F#之优雅
    Steve Jobs explains objectoriented programming
    c# 之 dynamic关键字
    Eric Schmidt 之关于 Steve Jobs
    面向过程vs面向对象
    转 命令,不要去询问(Tell, Don’t Ask)
    转 函数式编程的10年演化:越来越纯
    网络流学习笔记——简单题
    网络流学习笔记——难题
    线性代数学习笔记
  • 原文地址:https://www.cnblogs.com/qrlozte/p/4971088.html
Copyright © 2011-2022 走看看