I recently had to face a fairly complex issue regarding lib management, but I would be very surprised to be the first one.
Let's imagine you are creating a library (static or dynamic) called lib1
in C. Inside lib1
are a few functions that are exposed through an API, and a few other ones which remain private.
Ideally, the private functions would be static
. Unfortunately, let's assume one of the source files, called extmod.c
, come from another project, and it would be beneficial to keep it unmodified. Therefore, it becomes unpractical to static
the functions it defines.
As a consequence, all the functions defined into extmod
are present into lib1
ABI, but not the API, since the relevant *.h
is not shipped. So no one notice.
Unfortunately, at later stage, someone wants to link both lib1
and another lib2
which also includes extmod
. It results in a linking error, due to duplicate definitions.
In C++
, the answer to this problem would be a simple namespace. In C, we are less lucky.
There are a few solutions to this problem, but I would like to probe if anyone believes to have found an efficient and non-invasive way. By "non-invasive", I mean a method which avoids if possible to modify extmod.c
.
Among the possible workaround, there is the possibility to change all definitions from extmod.c
using a different prefix, effectively emulating namespace. Or the possibility to put the content of extmod.c
into extmod.h
and static everything. Both method do extensively modify extmod
though ...
Note that I've looked at this previous answer, but it doesn't address this specific concern.