0

How to add 2 different C libraries with same name but having entirely different functionalities without changing the name?

For example one s/w product comes with lib named libabc.so And my lib is also having the same name libabc.lib.

So, how I can use the both the lib at the same time, without conflicting at runtime

  • 2
    Find some other way to do what you need to do. Alhtough there are probably some operating-system specific hackery to make it happen, it's not worth the trouble. It easier to rename your own library. – Sam Varshavchik May 30 '20 at 22:56
  • `.so` is generally for Linux and `.lib` is Windows. Are you sure they are for the same platform? Which OS and compiler are you using? Is it just the library name that is the same or do they contain overlapping symbol names as well? – kaylum May 30 '20 at 22:59
  • Yes, its easier to rename but that not the case for me. – nitin srivastava May 30 '20 at 23:01
  • 2
    Let me ask you a counterquestion... where, do you think, is the client of your library going to *put* said library? It can't be placed in the same directory as the third-party libabc, because of the name colision... so, two libraries with the same name becomes a headache even *before* you actually want to link against them. Better rename your lib... – DevSolar May 30 '20 at 23:01
  • Can you please some of the "operating-system specific hackery" to make this happen ? – nitin srivastava May 30 '20 at 23:01
  • @kaylum - my bad, yes both are .so and the compiler is gcc. Its just the name which is common, both .so's are entirely different. – nitin srivastava May 30 '20 at 23:05
  • Can you please describe the libraries a bit better? Are you statically linking them, in which case it's a compile-time issue only, or do you have a shared object where it's a runtime concern? And can you please be a bit more specific why you believe you can't rename things? – Steve Friedl May 30 '20 at 23:05
  • 1
    Does this answer your question? [How to rename a shared library to avoid same-name conflict?](https://stackoverflow.com/questions/19739828/how-to-rename-a-shared-library-to-avoid-same-name-conflict) – kaylum May 30 '20 at 23:07
  • ... and even if you get this to work, it smells like it's going to be a security nightmare. – Steve Friedl May 30 '20 at 23:11
  • 1
    How about create a symbolic link for the static lib so that you can link it with another name? (I don't know if it works, but I recommend to try it out) – eerorika May 30 '20 at 23:14
  • The operating system specific hackery: on Linux one can use `dlopen()` to open and load a specific shared library at a particular location. You cannot simply call functions from that library, as usual. You must use additional functions to find the pointer to each exported library function, and invoke it via the pointer. C++ code? Have to figure out the mangled symbol name, and find it! Again: it's easier to just rename the library. I can't think of any valid reason why all this pain will be worth it. – Sam Varshavchik May 30 '20 at 23:35

1 Answers1

0

Instead of linking with -labc link with the full file library file paths like /usr/local/lib/libabc.a ./mylib/libabc.a for example.

If you do that the fact that they have the same name shouldn't matter.

What may conflict is if both libraries export symbols with identical names.

If header files also have the same name (e.g. abc.h) your #include statements may also need full paths to make sure you're including the right file.

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40