I have to link two libraries, say A and B. Some of the files are common in both libraries. So, I declare functions in library A inside a namespace, say abc. So, in A and B, a function func looks like below:
[ in A]
namespace abc {
extern "C" void func();
}
[in B]
extern "C" void func();
While building the project, compiler throws linking errors saying multiple definitions of function func. Isn't the function func in A inside the namespace or is there some problem with extern "C" functions. If there is, then how can I differentiate them both?
When you use Extern "C" you are turning off name mangling so you lose the namespace information as C has no such concept. This causes a duplicate definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With