Why is the startup of an App on linux slower when using shared libs?

后端 未结 6 1868
执笔经年
执笔经年 2021-01-23 05:11

On the embedded device I\'m working on, the startup time is an important issue. The whole application consists of several executables that use a set of libraries. Because space

6条回答
  •  礼貌的吻别
    2021-01-23 06:17

    Bacause shared libraries have to be linked to at runtime, usually by dlopen() or something similar. There's no such step for static libraries.

    Edit: some more detail. dlopen has to perform the following tasks.

    • Find the shared library
    • Load it into memory
    • Recursively load all dependencies (and their dependencies....)
    • Resolve all symbols

    This requires quite a lot of IO operations to accomplish.

    In a statically linked program all of the above is done at compile time, not runtime. Therefore it's much faster to load a statically linked program.

    In your case, the difference is exaggerated by the relatively slow hardware your code has to run on.

提交回复
热议问题