Lib and DLL linking to an exe error “cannot read at 0x300”

后端 未结 1 1222
耶瑟儿~
耶瑟儿~ 2020-12-17 16:41

I have a general question about how .dll/.libs are suppose to be used. I am creating a .dll to be used for my project, however, I noticed that when I go to compile I need to

相关标签:
1条回答
  • 2020-12-17 17:17

    The .lib contains stubs for the functions etc. that are exported by the DLL. You link the .lib into your EXE and now your EXE knows how to call the functions. But of course there's no function there - the calls go nowhere. At load time, when the operating system loads your EXE it also loads your DLL, and then it patches the EXE - where the EXE calls into the stub, the loader replaces that with a call into the real function in the DLL.

    Normally you do not need to ship the .lib to your customers. However, if your customers want to write their own EXEs that use your DLL then you will need to send them the .lib so that they can link their EXE against it.

    Linker error LNK1107 means that you've tried to link to the DLL rather than to the .lib. That's always wrong, because by definition a DLL is linked dynamically at runtime, rather than statically at build time.

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