I'm trying to compile a cpp file that uses include headers from 2 folder locations. Both the folders has lot of headers that are necessary for my file.
Now, one of the header file is present in both the folders, but the problem is they are of different version. Hence the functions in that common header have same name but different API signature.
Something like this:
Folder A:
- foo.hpp
- bar1.hpp
- bar2.hpp
- bar3.hpp
Folder B:
- foo.hpp
- bar4.hpp
- bar5.hpp
- bar6.hpp
API of function foobar from foo.hpp of folder A:
void foobar(arg1, arg2);
API of function foobar from foo.hpp of folder B:
void foobar(arg1, arg2, arg3);
#include "foo.hpp"
#include "bar1.hpp"
...
#include "bar4.hpp"
...
...
int main(){
...
foobar (arg1, arg2);
...
}
g++ main.cpp -o MyExe -I< path-to-folder-A > -I< path-to-folder-B >
This throws the errors like multiple redefinition of function, no matching function call etc., for various functions in the header.
So, my question is: Are there any flags to tell the compiler only to consider the definition found from folder A and ignore the one from folder B?
Note on code limitations: I cannot alter the folders or files of A and B in any manner. Neither can I give absolute paths to the headers instead of -I.
foo.hpp
, from the same directory. As such, waving a magic wand and making one of them disappear won't work. You will have to split your code into different source modules and compile them separately, with each module using one of the-I
options. And, of course, there is no guarantee that the resulting frankencode will link correctly, but that will be another problem you will need to solve at some point. – Sam Varshavchik#ifndef MY_HEADER
etc.)? – Max Langhof