I am writing a wrapper for multiple static libraries that are implementing similar functionality. Two of those libraries share the same class names and (because of their age) don't make use of namespaces.
This lead to compiler errors in my program because the class has two different implementations.
I fixed the compiler issues by redefining the class name using #define for one of the libraries. Which looks like this:
#define foo lib_foo
#include "lib.h"
#undef foo
At first, this seemed to work. But now, when assigning a value to an instance of lib_foo, I get this error:
undefined reference to `lib_foo::operator=(lib_foo const&)'
The class seems to override the assignment operator (and obviously has other functions which take a lib_foo as an input parameter) and the linker can't find the corresponding implementations for these functions, because they are defined in a .cpp file which doesn't get the #define treatment.
I can't introduce namespaces to the original lib (it's not my lib and it would break compatibility to other projects).
My plan is to change the occurences of foo to lib_foo in the object file of the library, but I don't know how to do this.
I found this post which deals with this kind of problem but for c funtions and in a much simpler manner.
Does someone have experience with this? Or is there an easier way to handle this problem?
I am writing a wrapper for multiple libraries. This should be solution for your problem. Most probably issue is caused by fact that details of wrapped library are leaking outside of wrapper by its header files. Make sure that public headers of the wrapper do not use any symbols to library it wraps. Using this#define foo lib_foois wrong since it just hides issue in compilation time (and introduces UB). Also please specify if wrapper is a shared library.