简体   繁体   中英

How to force a DLL dependency even when no symbols are directly used by EXE?

I have A.DLL that depends on B.DLL. A.DLL contains some initialization code ( DllMain ) that registers stuff with B.DLL.

I also have executable E.EXE that does not directly reference any A.DLL symbols but it uses A.DLL's stuff through generic interfaces obtained from B.DLL.

The problem is that A.DLL is never loaded into E.EXE's process because none of its exported symbols are imports of E.EXE.

Can I force A.DLL to be loaded into the process without actually referencing A.DLL's symbols in E.EXE and without inverting the dependency (or creating a dependency loop) between A.DLL and B.DLL, and without using explicit LoadLibrary() call?

EDIT: The problem has been produced on Windows with Visual Studio but portability is a concern, thus LoadLibrary() is not usable.

You can specify the /INCLUDE linker option and provide a symbol exported by A.dll .

Even though your executable does not really reference that symbol, that option will force the linker to add A.dll to the dependencies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM