Does Windows have a __declspec equivalent to Unix GCC's __attribute__((weak))?

后端 未结 2 787
终归单人心
终归单人心 2021-01-14 18:59

I want to import some C code but override its main() function. I can do this in Unix by prefacing the C code\'s main declaration with __attribute__((weak)

相关标签:
2条回答
  • 2021-01-14 19:36

    There's another way with MSVC that I think would work if you care to use it.

    /*
     * pWeakValue MUST be an extern const variable, which will be aliased to
     * pDefaultWeakValue if no real user definition is present, thanks to the
     * alternatename directive.
     */
    
    extern const char * pWeakValue;
    extern const char * pDefaultWeakValue = NULL;
    
    #pragma comment(linker, "/alternatename:_pWeakValue=_pDefaultWeakValue")
    

    See this old SO answer for some other options.

    0 讨论(0)
  • 2021-01-14 19:47

    There's also __declspec(selectany)

    0 讨论(0)
提交回复
热议问题