How to build an image (DLL/EXE) when two of its included libraries have the same symbol (say function/variable) using VC++





5.00/5 (1 vote)
If the .lib files you're linking to represent some .dll files somewhere else, you can do the following:void main(){ FunB(); // from external_1.lib FunC(); // from external_2.lib // FunA(); // from external_1.lib / external_2.lib ???? typedef void (WINAPI *...
If the .lib files you're linking to represent some .dll files somewhere else, you can do the following:
void main()
{
FunB(); // from external_1.lib
FunC(); // from external_2.lib
// FunA(); // from external_1.lib / external_2.lib ????
typedef void (WINAPI * funa_ptr)(void);
funa_ptr pfunA = ::GetProcAddress(::GetModuleHandle(_T("external_1.dll")), _T("FunA"));
if (NULL == pfunA)
{
// TODO: Handle the error.
}
pfunA();
}
- The linker should not complain, since the conflicting functions are not statically linked.
::GetModuleHandle
should work, since both DLLs were statically linked (and loaded before the .exe wheremain()
is defined)
static
libraries, you can encapsulate one of them within a DLL of your own, replacing the functions by renamed versions:
// In MyDll.cpp: link to external_1.lib
void MyFunA()
{
FunA();
}
void MyFunB()
{
FunB();
}
You may link your executable to external_2.lib, and your DLL to external_1.lib, thus avoiding name clashes.
Hope this helps.