I am writing a C++ DLL (Plugin.dll) which depends on a static library (lib_a.lib).
I also maintain lib_a, which has a source file Stuff.cpp. In stuff.cpp two functions are implemented:
#include <third_party_library/MyHeader.h>
...
//This function depends on third_party_library
bool Stuff::Foo(MyType* arg1)
{
bool success = ThirdPartyLib::Bar(arg1); //Declared in third_party_library/MyHeader.h
if (!success) { return false; }
}
//This function does not depend on third_party_library
bool Stuff::Foo(MyType* arg1, MyType2* arg2)
{
bool success = Stuff::SomeOtherFunc(arg1, arg2);
if (!success) { return false; }
}
...
In Plugin.dll, there is a call to the second function, which does not depend on third_party_library. There are no calls to the first function in Plugin.dll (and I have traced every possible call stack to verify that there can be no downstream calls to the first function). Therefore, Plugin functions do not actually call anything depending on third_party_library (none of Plugin's other dependencies depend on third_party_library; the only way for this dependency to occur would be through lib_a as described).
When I build Plugin in the release configuration, then check dependencies in the Visual Studio terminal window using the command dumpbin /DEPENDENTS C:\path\to\build\x64\Release\Plugin.dll
, third_party_library.dll is not listed as a dependency. However, when I build Plugin in the debug configuration and check the dependencies of Plugind.dll, third_party_libraryd.dll (the debug version of third_party_library) is listed as a dependency. I know that this dependency comes from Plugin's call to Stuff:Foo(MyType* arg1)
because the dependency is eliminated if I comment out this call and rebuild.
I assumed this discrepancy was due to linker optimizations (/OPT:REF) being enabled for the release configuration and not the debug configuration, but enabling linker optimizations in the debug configuration did not solve the problem.
In fact, I even started from scratch and made a new debug configuration that was an exact copy of my release configuration except for the following:
- Debug has the preprocessor definition _DEBUG, Release has NDEBUG
- In 'Linker options->Additional Dependencies,' the Debug configuration lists the debug version of each library while the Release configuration lists the release version of each library
- Debugger information is generated in the Debug build (/Debug/Zi)
(This configuration is not so useful for actual debugging, I just made it to get to the bottom of the problem).
Yet I still get a dependency on third_party_libraryd.dll in my debug build. I would really like to eliminate this unused dependency so I don't have to keep this dll in my repo (I have this same problem with several third party libraries, so they are sizable all put together) or distribute it on the occasion I have to deploy a debug build internally.
So my question is, why might Plugind.dll still depend on third_party_libraryd.dll and is there a way for me to eliminate this dependency?
The compiler command line options in the Debug configuration are:
/JMC /GS /GL /W3 /Gy /Zc:wchar_t /I"C:\our\include\paths" /Zi /Gm- /O2 /sdl /Fd"x64\Debug\vc141.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_WINDOWS" /D "CV4" /D "G3D9" /D "_USRDLL" /D "SIMPLENATIVELIBRARY_EXPORTS" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /D "_AFXDLL" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MDd /FC /Fa"x64\Debug" /EHsc /nologo /Fo"x64\Debug" /Fp"x64\Debug\Plugind.pch" /diagnostics:classic
The compiler command line options in the Release configuration are:
/JMC /GS /GL /W3 /Gy /Zc:wchar_t /I"C:\our\include\paths" /Gm- /O2 /sdl /Fd"x64\Release\vc141.pdb" /Zc:inline /fp:precise /D "NDEBUG" /D "_WINDOWS" /D "CV4" /D "G3D9" /D "_USRDLL" /D "SIMPLENATIVELIBRARY_EXPORTS" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /D "_AFXDLL" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /FC /Fa"x64\Release" /EHsc /nologo /Fo"x64\Release" /Fp"x64\Release\Plugin.pch" /diagnostics:classic
The linker command line options in the Debug configuration are:
/OUT:"C:\path\to\build\x64\Debug\Plugind.dll" /MANIFEST /LTCG:incremental /NXCOMPAT /PDB:"C:\path\to\build\x64\Debug\Plugind.pdb" /DYNAMICBASE "lib_a_debug.lib" "third_party_libraryd.lib" "other_dependencies_debug.lib" /IMPLIB:"C:\path\to\build\x64\Debug\Plugind.lib" /DEBUG /DLL /MACHINE:X64 /NODEFAULTLIB:"LIBCMT" /OPT:REF /INCREMENTAL:NO /PGD:"C:\path\to\build\x64\Debug\Plugind.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Debug\Plugind.dll.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\our\library_paths" /TLBID:1
The linker command line options in the Release configuration are:
/OUT:"C:\path\to\build\x64\Release\Plugin.dll" /MANIFEST /LTCG:incremental /NXCOMPAT /PDB:"C:\path\to\build\x64\Release\Plugin.pdb" /DYNAMICBASE "lib_a.lib" "third_party_library.lib" "other_dependencies.lib" /IMPLIB:"C:\path\to\build\x64\Release\Plugin.lib" /DEBUG /DLL /MACHINE:X64 /NODEFAULTLIB:"LIBCMT" /OPT:REF /INCREMENTAL:NO /PGD:"C:\path\to\build\x64\Release\Plugin.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Release\Plugin.dll.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\our\library_paths" /TLBID:1