0

I am getting an undesired loading of a shared library which has already been loaded.

I have a binary(test_bin) which is supposed to load a shared library(libtest.so). Also, I have a C python extension module(extension.so) which also loads libtest.so

Now, when I start the binary with an embedded python interpreter and import the extension module, I get a lot of errors happening due to the static globals in the library getting initialized twice.

My question is, in this case why is libtest.so loaded during the extension import even though it has already been loaded by the binary(have confirmed this with lsof)

Note: The version, name and location of the shared library used by the binary and the python extension are all same(verified by ldd)

Invocation:

./test_bin
In [1]: from some.location import extension
    # errors due to double initialization

Please let me know if you need any other information

11
  • perhaps your libtest.so is position-independent (compiled as gcc -fPIC), then I think it can be loaded twice Commented Oct 21, 2015 at 12:11
  • Yes it is PIC. I think we need position independent code for making a shared library, don't we? Commented Oct 21, 2015 at 12:12
  • Please note that the library is also created by me so any help to create it in a way which solves the problem would be appreciated. Commented Oct 21, 2015 at 12:14
  • @KanishkaKhandelwal it depends what you mean by shared library. Commented Oct 21, 2015 at 12:21
  • @PeterWood By shared library I mean a library which is dynamically loadable. In this case, my library is only to be used in these 2 cases(to be dynamically loaded by the binary and by the extension module). Note that the extension module can also be imported without being embedded by the binary. So, do you have any suggestions here? Commented Oct 21, 2015 at 12:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.