can I declare a global variable in a shared library?

前端 未结 2 929
谎友^
谎友^ 2021-02-19 22:24

Can I declare a global variable inside a library that is later compiled into a shared object ? Is it safe to reference it from other libraries or the main application code by de

2条回答
  •  伪装坚强ぢ
    2021-02-19 22:49

    Yes, libraries can contain global variables.

    But depending on compiler/linker options, they might be not visible. E.g. it is common practice, that libraries are built with -fvisibility=hidden and that only certain symbols are exported (by linker map or explicit __attribute__((__visibility__)) tags).

    Your "large" project has been probably built in such a way.

    The high address might also indicate, that variable is some kind of other symbol (function) in another library.

提交回复
热议问题