dfranx / SHADERed

Lightweight, cross-platform & full-featured shader IDE
https://shadered.org/
MIT License
4.33k stars 272 forks source link

Link prebuilt binaries to libGLEW.so #133

Open SirJonthe opened 3 years ago

SirJonthe commented 3 years ago

When trying to run the prebuilt binary of the application (as hosted on shadered . org) for Linux on a cutting edge distribution (such as Arch) you get the following error:

./SHADERed: error while loading shared libraries: libGLEW.so.2.1: cannot open shared object file: No such file or directory

The prebuilt versions of the binaries for Linux link against libGLEW.so.2.1. This will fail to launch the application on distributions that come with newer versions of GLEW (such as 2.2). A fix could be to rebuild the prebuilt binaries to link against the a generic GLEW library, libGLEW.so (no version number).

dfranx commented 3 years ago

Thanks for reporting this. I'd love to link against generic libraries without the version in the next build but unfortunately I am not sure how to achieve this. Is there some kind of CMake flag that I can use or? Not really experienced with this kind of stuff.

SirJonthe commented 3 years ago

Doing some investigation into the issue, this seems to (partially) be an issue with GLEW. From my understanding, passing -lGLEW to gcc or g++ will make the linker look at the "soname" of the specified library and insert that into the output program ELF table. Normally, developers only use major version numbers in their soname as they expect all major versions to be compatible with each other, but it seems GLEW decided to go a different route, making the binary look for a specific GLEW version that not only conforms to the major version numbering of the one used to build the application, but also the minor version (see https://sourceforge.net/p/glew/bugs/262/). This can be seen using readelf in a shell:

readelf -a /lib/libGLEW.so | grep SONAME

My system outputs "Library soname: [libGLEW.so.2.2]", while for others this might be "Library soname: [libGLEW.so.2.1]" (note the path to libGLEW.so might be different on different systems).

So far I can only think of two solutions which are incredible hacky; One solution involves symlinking to the existing GLEW version via the linked GLEW version, and the other involves modifying the ELF to point to libGLEW.so. There might be some compiler setting that ignores the soname of the linked library, but I am unaware of such settings at this point.

ericonr commented 3 years ago

A library's choice of soname should probably be respected, since SONAMEs can and often do break ABI compatibility. Furthermore, many distros only install the unversioned libGLEW.so symbol in development packages, so people would be required to install that in order to use the pre-built version.

SirJonthe commented 3 years ago

@ericonr Normally, I would agree if it were not for the fact that the versioning has been reported as a bug and is still an open ticket. Bug or not, symlinking on my computer has not resulted in any failure on the part of Shadered as of writing, but, admittedly, has limited empirical evidence as to its effectiveness as a general solution. I may be misunderstanding your second sentence, but installing the unversioned libGLEW.so does not actually mitigate any problem, as the unversioned libGLEW.so is generally only a symlink to a versioned libGLEW.so.VERSIONNAME. I apologize in advance if I have not understood your second sentence correctly.

ericonr commented 3 years ago

Normally, I would agree if it were not for the fact that the versioning has been reported as a bug and is still an open ticket.

I wasn't aware of this one. Interesting.

My second point was about somehow linking the prebuilt binary to an unversioned library: most distros don't have that symlink in default packages, only in the development ones (something like openssl-dev). This would break users from distros like that.

And don't worry, my phrasing could have been better :)

rncar commented 2 years ago

Arch linux user too. I have fixed it symlinking /usr/lib/libGLEW.so to libGLEW.so.2.1 in the shadered directory

ln -s /usr/lib/libGLEW.so libGLEW.so.2.1

Now we need to load libraries from the current directory

export LD_LIBRARY_PATH=./
ZanyXDev commented 1 year ago

OS Linux blackhole 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.38-1 (2023-07-14) x86_64 GNU/Linux need add packets: sudo apt install glew-utils libglew2.2 in app folder create link: ln -s /usr/lib/x86_64-linux-gnu/libGLEW.so.2.2 libGLEW.so.2.1 export library path: export LD_LIBRARY_PATH=./ run app and fine.