Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22001

How to solve duplicate function problem when linking libraries?

$
0
0

I have executable, that links against library1.so. Library1.so contains a function called json_object().

I am trying to enhance library1 where library1.so would link against library2.so. Unfortunately, library2.so links against another library called libjansson.so that also exports symbol called json_object() (APIs between both json libraries are very different).

Now I am observing a run-time error where library2.so incorrectly calls into json_object() implementation from library1.so. All I want is that calls originating from library2.so to json_object() call into libjansson.so instead. and the calls originating from the executable or library1.so call into json_object() implementation from library1.so

How to solve this kind of problem?

Here is what I tried - I built libjansson as a static library and linked it against library2.so so that it would not appear in its ldd output. However, now I am getting following build time error when I try to build the executable:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libjansson.a(value.o): in function `json_object':value.c:(.text+0x189): multiple definition of `json_object'; lib/.libs/liblibrary1.a(json.o):/home/library1/lib/json.c:123: first defined here

Viewing all articles
Browse latest Browse all 22001

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>