I want to include two libraries which i built from the source code.
To go more into detail: These libraries are in general the same, except for some parameters which are different and set by a
#define Mode *X*
X describes the mode and describes which parameter set to use. E.g.
For x = 2 i want to use
#define N 3
#define Q 4
etc
In one library my x is for example 2 and in the other 3 which makes N 4 and Q 6 e.g.
Also these libraries contain the same functions which operate little different depending mode which is set.
I Need to include both of them and keep the options open to use both parameter sets.
Any ideas how to implement this correctly and clean? The whole thing only depends on the mode and to rename all containing functions and variables is unfortunately no option. But i have access to the source code and can make some changes.
I tried to built the libraries and include them in my main program but obviously i have a lot of naming collisions and the first definition which is found by the linker is set to be correct.
Another problem is that all the header files start with e.g.
#ifndef CONFIG
#define CONFIG
Which is standard and ok but I have all files two times so only the first header which is included by the linker sees that it isnt already defined and for the second its already defined so none of the code below is executed by the compiler.
Has someone a good idea how to solve this elegant?
I heard something about namespaces but i am not sure if this is even available for C and the right way to go.
BR
question from:https://stackoverflow.com/questions/65927679/c-libraries-with-the-same-function-and-variable-names