I am trying to implement sound in my program using the IrrKlang library. I am in Ubuntu 22.04 LTS and using g++ version 11.3.0.
The program compiles but when I try to run it I get this error message:
./main: error while loading shared libraries: libIrrKlang.so: cannot open shared object file: No such file or directory
This is the console output when trying to compile and run:
make run
mkdir -p bin/Linux
g++ -std=c++11 -Wall -Wno-unused-function -g -I ./include/ -L ./lib/ -o ./bin/Linux/main src/main.cpp src/glad.c src/textrendering.cpp src/tiny_obj_loader.cpp src/stb_image.cpp ./lib-linux/libglfw3.a -lrt -lm -ldl -lX11 -lpthread -lXrandr -lXinerama -lXxf86vm -lXcursor -lIrrKlang
cd bin/Linux && ./main
./main: error while loading shared libraries: libIrrKlang.so: cannot open shared object file: No such file or directory
make: *** [Makefile:10: run] Error 127
The Makefile
is in the project's root folder.
libIrrKlang.so
is in (project_folder)/lib/
.
The compiled binary named main
is placed in (project_folder)/bin/Linux/
.
I've tried placing the compiled binary in the root of the project folder (and modifying the Makefile accordingly), and that solves the error, but causes other issues because the program depends on the original folder structure with the executable being in ./bin/Linux
.
This question has a similar problem and setup to mine, so i tried that solution, by adding the following to my g++ command:
--Wl,-rpath='../../lib'
But I get this error:
g++: error: unrecognized command-line option ‘--Wl,-rpath=../../lib’
Is there a way to use this library while maintaining this folder structure?
The answer to the question you linked is the correct approach. Adding -Wl, -rpath=/../../lib will allow the linker to find your local shared library. It looks like the reason it is not working for you, is that --Wl should be -Wl which is causing the unrecognized command-line option error