force visual studio to link all symbols in a lib file

后端 未结 6 1542
清酒与你
清酒与你 2020-12-09 16:19

Is there any way to force visual studio to link all symbols from a lib file into the dll as atm it is optimizing \"unused\" functions which are needed by the program using t

6条回答
  •  暖寄归人
    2020-12-09 16:40

    Tested in MSVC2k17...

    __pragma(comment(linker,"/export:REGISTERfunc"));
    void REGISTERfunc() { printf("I'm linked!\n" ); }
    

    Totally works. This can even be inside a statically linked .lib and will carry through all the way to the output executable and beyond!

    EDIT: You can even put it in a macro for bonus awesome points!

    EDIT: Another note: You must link-time code generation enabled. /LTCG ... something

提交回复
热议问题