wilx
wilx

Reputation: 18268

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.

Upvotes: 1

Views: 2760

Answers (1)

Frédéric Hamidi
Frédéric Hamidi

Reputation: 263157

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.

Upvotes: 7

Related Questions