I heard somewhere that all Windows .DLLs must contain definitions for every symbol it references, so a .DLL file like this would never compile since it doesn't implement bar()
.
void bar();
__declspec(dllexport)
void foo() {
bar();
}
I think the analogy is that .DLLs are essentially executables with a different entry point, so they have to have all referenced defined, like an executable.
But in a Unix environment, I can compile this to a .so file with no problem. I can then use dlopen(path, RTLD_NOW | RTLD_GLOBAL);
from the host application to load the library and merge the host's symbols with the library's. If the host defines bar()
, the library will simply call that function.
I can't just re-define everything into the .DLL file, because in my application the library uses thousands of symbols from the host. Using MinGW or possibly Visual C++, is there really no way to use a symbol from the host by leaving it undefined in the .DLL and merging it when loaded? I don't want to set thousands of callback functions in the .DLL either, because that gets difficult with C++ methods.