Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

craftos: error while loading shared libraries: craftos2-lua/src/liblua.so: cannot open shared object file: No such file or directory #237

Closed
walksanatora opened this issue Feb 4, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@walksanatora
Copy link

Describe the bug
A clear and concise description of what the bug is.

getting craftos: error while loading shared libraries: craftos2-lua/src/liblua.so: cannot open shared object file: No such file or directory
when running from outside the folder

To Reproduce
Steps to reproduce the behavior:
build the craftos pc binary with make (i ran with -j4 for using all 4 of my cores)
head to another folder
try to run the binary either via a relative path or a symlink to the craftos binary

Expected behavior
A clear and concise description of what you expected to happen.
the liblua should either be built in or be able to be resolved instead of from the local path

Environment (please complete the following information):

  • OS: [e.g. Windows 10] Linux Mint 20
  • OS Version: [e.g. 2004] (this can be found in Settings -> System -> About)
  • CraftOS-PC Version: [e.g. v2.2] v2.6.4
  • Compiled from source? [Yes] [No] (if in doubt, choose No) yes
@walksanatora walksanatora added the bug Something isn't working label Feb 4, 2022
@MCJack123
Copy link
Owner

This is due to how the build process works. You need to use the patchelf utility to change the path it looks for the library at, then make a link next to the executable:

patchelf --replace-needed craftos2-lua/src/liblua.so libcraftos2-lua.so craftos
ln -s craftos2-lua/src/liblua.so libcraftos2-lua.so

I can't make this happen automatically, as patchelf is platform-specific and is not universal across Linux distros.

@MCJack123 MCJack123 pinned this issue Feb 5, 2022
@walksanatora
Copy link
Author

mabey do something like this during the craftos target
https://stackoverflow.com/a/34756868/14969319
(only execute the patchelf step if patchelf is on path)

@walksanatora
Copy link
Author

(i am testing locally and making a patchelf target that includes the patchelf fix)

@walksanatora
Copy link
Author

patchelf_target.patch
a simple patch that patches Makefile.in to add the patchelf target which also runs the craftos target
(and adds to the clean target to remove the symlink to the lib)

@walksanatora
Copy link
Author

should i pr this patch into the main repo as a extra target (also there are some cases where you refrence the craftos target directly instead of using @OUT_TARGET@)

@khankul
Copy link

khankul commented Oct 7, 2023

Same issue with the AppImage. Can't compile from source for now, so it prevents me from using the software. I suppose this should get fixed.

@CelDaemon
Copy link

CelDaemon commented Jul 18, 2024

This is due to how the build process works. You need to use the patchelf utility to change the path it looks for the library at, then make a link next to the executable:

patchelf --replace-needed craftos2-lua/src/liblua.so libcraftos2-lua.so craftos
ln -s craftos2-lua/src/liblua.so libcraftos2-lua.so

I can't make this happen automatically, as patchelf is platform-specific and is not universal across Linux distros.

After experimenting a bit with building the project manually, it seems to be possible to fix this to not force the use of patchelf.

By renaming the lua library output from liblua to libcraftos2-lua, it's possible to set the craftos2-lua/src directory as a library lookup directory using -Lcraftos2-lua/src in the configure.ac linker flags, and adding -lcraftos2-lua in the libs.

This way the output binary will be set to load libcraftos2-lua.so from ld automatically, without any package-time patching.

The only annoying thing is that the binary will have to be run using LD_LIBRARY_PATH="craftos2-lua/src" during development, but I'm pretty sure there should be a way to solve that.

(I also haven't looked into how this ties into the windows version build, but I'm hoping it's not too difficult to make that work with it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants