I have a problem at link between two libraries libA.a (static) and libB.so (dynamic), created from C sources.
In one of the source files used to generate libB.so, I have the following functions :
static uint64_t unassigned_mem_read(void *opaque, hwaddr addr, unsigned size) { ... }
static void unassigned_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { ... }
When I run nm libB.so | grep unassigned_mem I've got:
00000000004662a7 t unassigned_mem_read
0000000000466337 t unassigned_mem_write
And in a source file used for making libA.a, I've got:
extern uint64_t unassigned_mem_read(void *opaque, hwaddr addr, unsigned size);
extern void unassigned_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size);
and a bit further these methods are called.
When I compile, everything is ok. But then at link, I have:
[build] qmg-mmio.c:47: undefined reference to 'unassigned_mem_read'
[build] qmg-mmio.c:84: undefined reference to 'unassigned_mem_write'
When I do nm libA.a | grep unassigned_mem I've got:
U unassigned_mem_read
U unassigned_mem_write
I link in this order: libB.so, libA.a.
As the symbols are the same, what can make them not being resolved?
Moreover when I compile all the sources together, then I have no problem at link. Is there a subtelty when linking a static and a dynamic library altogether that I miss?
statickeyword from both functions, ie. export them.libBsource [the easiest option], you might be able to use some object editing/linker tools to changelibB.soso that you change the linkage fromt(static/invisible) toT(global). If you can't find one, you could write your own small utility that uses library API calls (e.g. eitherlibelf.soorlibbfd.so) to do the heavy lifting. But, again, if you have the source and control it, you could try building it with-Dstatic=/**/. That may work as well.