Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Set SONAME on created libraries #190

Open
incaseoftrouble opened this issue Feb 22, 2022 · 4 comments
Open

Set SONAME on created libraries #190

incaseoftrouble opened this issue Feb 22, 2022 · 4 comments

Comments

@incaseoftrouble
Copy link

After some debugging (I'm trying to load prism's libraries without messing with LD_LIBRARY_PATH through System.load), I noticed that prism's shared libraries are created without SONAME, which causes issues on linux.

To fix this problem, one would need to add -Wl,-soname,$(LIBPREFIX)dd$(LIBSUFFIX) to $(LDFLAGS) when building for linux. I'm currently hacking this issue by running patchelf.

I'm not an expert on anything C / C++ related, so this might be a bad idea, but as far as I understood, doing so is recommended.

@davexparker
Copy link
Member

Hi @incaseoftrouble. Thanks for investigating. I know some people have had at least partial success with System.load over the years, although I've never found a solution that works reliably across all our platforms (especially Mac) without using (DY)LD_LIBRARY+PATH. In principle I have no problem with adding this to the Linux build process, if it doesn't break anything else. Two questions: How does Java find the directory containing the libraries? Via the classpath? And are additional System.load calls needed for this to work?

@incaseoftrouble
Copy link
Author

Well, here's the problem, I have no idea how it works exactly. Even after patching with patchelf I managed to load all libraries but prism then later on still failed with an unsatisfied link error (or maybe I did something wrong). Neither do I know whether this would break anything, unfortunately. Maybe some other contributor knows more about these things?

@davexparker
Copy link
Member

Something to do with shared libraries depending on each other? The reason for my second question was that I found this, which (I think) worked for someone else previously: davexparker@5280e78.

@incaseoftrouble
Copy link
Author

Yes, let me try to explain what I think I understood:

If loading via System.loadLibrary, the .so files need to be on LD_LIBRARY_PATH (java.library.path seems to not be sufficient if the .so files depend on others)

Loading via System.load works if done in the correct order if the libraries have SONAME set. Basically, as I understand it, I e.g. load libdd.so (which works) but loading libodd.so fails because it can't find libdd.so - in this case the lookup is not done based on the loaded library file name but on its SONAME. So the libdd I loaded previously is sort of stored as an "unnamed" library and loading libodd.so fails because there is no library loaded with name libdd.so.

So I added the SONAME via the patch, but prism loads via System.loadLibrary which somehow didn't work for reasons I don't understand. At this point I gave up and customized my startup script to set LD_LIBRARY_PATH (I'm using prism as a library, so I cannot directly use prism's scripts).

I just openend this issue, since I think it might be the "proper" way to do it (lpsolve for example has SONAME set).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants