Static variable initialization over a library

前端 未结 3 805
名媛妹妹
名媛妹妹 2020-12-03 15:58

I am working on a factory that will have types added to them, however, if the class is not explicitly instiated in the .exe that is exectured (compile-time), then the type i

3条回答
  •  醉梦人生
    2020-12-03 16:23

    When you are linking with a static library, you are in fact extracting from it the object files which provide symbols which are currently used but not defined. In the pattern that you are using, there is probably no undefined symbols provided by the object file which contains the static variable which triggers registration.

    Solutions:

    • use explicit registration
    • have somehow an undefined symbol provided by the compilation unit
      • use the linker arguments to add your static variables as a undefined symbols
      • something useful, but this is often not natural
      • a dummy one, well it is not natural if it is provided by the main program, as a linker argument it main be easier than using the mangled name of the static variable
    • use a linker argument stating that all the objects of a library have to be included
    • dynamic libraries are fully imported, thus don't have that problem

提交回复
热议问题