Well, technically not, there is no way to have namespaces in the exact same way that C ++ does. Unfortunately, this leads to things like SDL2, which gives each function "SDL_". There is one solution to resolving conflicts between external libraries. Say we have a libfoo library that has a function
void do_foo(void *);
defined. You are trying to compile and link your program, but it turns out that the other library that you use, "libfu", also has this function. Now I would like to create some adapter library that renames the function with the corresponding prefix. So we will have the file "libfoo_f.h" that defines the function
void FOO_do_foo(void *);
and in "libfoo_f.c"
#include"libfoo_f.h" #include<libfoo.h> void FOO_do_foo(void *data) { do_foo(data); }
All this function provides a way to access libfoo do_foo without breaking your libraries. Honestly, I never had to do this because most libraries have well-structured, well-named interfaces that are hardly in conflict with other libraries.
source share