#Can t find sdl2 libs when running on linux ubuntu 23

27 messages · Page 1 of 1 (latest)

robust moss
#

I am doing a project that uses sdl2 and sdl-image on linux, i have the following directoy structure:
total 20
drwxrwxr-x 3 lucas lucas 4096 Feb 17 16:58 assets
drwxrwxr-x 2 lucas lucas 4096 Feb 20 12:57 bin
-rw-rw-r-- 1 lucas lucas 202 Feb 19 19:20 Makefile
drwxrwxr-x 2 lucas lucas 4096 Feb 17 21:51 src
drwxrwxr-x 4 lucas lucas 4096 Feb 17 21:39 third-party
and the following makefile:
CXXFLAGS = -w -Ithird-party/include
LDFLAGS = -Lthird-party/lib/SDL2 -lm -lSDL2main -lSDL2 -lSDL2_image

main: $(wildcard src/*.cpp)
g++ $(CXXFLAGS) $^ $(LDFLAGS) -o bin/main

run:
./bin/main
It builds with no problems but when executing: make run i get the following error:
./bin/main
./bin/main: error while loading shared libraries: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory
make: *** [Makefile:8: run] Error 127
and these are the third-party/lib/SDL2 folder contents:
total 27436
lrwxrwxrwx 1 lucas lucas 23 Feb 19 21:29 libSDL2-2.0.so.0 -> libSDL2-2.0.so.0.3000.0
-rwxr-xr-x 1 lucas lucas 8718240 Feb 19 21:24 libSDL2-2.0.so.0.3000.0
-rw-r--r-- 1 lucas lucas 15965264 Feb 19 21:24 libSDL2.a
lrwxrwxrwx 1 lucas lucas 28 Feb 19 21:29 libSDL2_image-2.0.so.0 -> libSDL2_image-2.0.so.0.800.2
-rwxr-xr-x 1 lucas lucas 858864 Feb 19 21:25 libSDL2_image-2.0.so.0.800.2
-rw-r--r-- 1 lucas lucas 1621862 Feb 19 21:25 libSDL2_image.a
-rwxr-xr-x 1 lucas lucas 1036 Feb 19 21:25 libSDL2_image.la
lrwxrwxrwx 1 lucas lucas 28 Feb 19 21:29 libSDL2_image.so -> libSDL2_image-2.0.so.0.800.2
-rwxr-xr-x 1 lucas lucas 951 Feb 19 21:24 libSDL2.la
-rw-r--r-- 1 lucas lucas 3948 Feb 19 21:24 libSDL2main.a
-rwxr-xr-x 1 lucas lucas 876 Feb 19 21:24 libSDL2main.la
lrwxrwxrwx 1 lucas lucas 23 Feb 19 21:29 libSDL2.so -> libSDL2-2.0.so.0.3000.0
-rw-r--r-- 1 lucas lucas 901654 Feb 19 21:24 libSDL2_test.a
-rwxr-xr-x 1 lucas lucas 879 Feb 19 21:24 libSDL2_test.la

What is the problem,i can t get it to work....!!???

proper slateBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

ember yacht
#

run ldd ./bin/main if you are dynamically linking the version should match or be backwards compatible. you could statically link libSDL2, but libsdl.org recommends against statically linking.

#

or try running LD_LIBRARY_PATH="<absolute path>/third-party/lib/SDL2:$LD_LIBRARY_PATH" ./bin/main

robust moss
#

Thank you,will try now!

proper slateBOT
#

@robust moss Has your question been resolved? If so, type !solved :)

robust moss
#

i ran ldd ./bin/main and got this:

#

linux-vdso.so.1 (0x00007fff40e32000)
libSDL2-2.0.so.0 => not found
libSDL2_image-2.0.so.0 => not found
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f667d200000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f667d5cd000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f667ce00000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f667d4e0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f667d609000)

#

and ran: LD_LIBRARY_PATH="/home/lucas/Programming/C++/Projects/Agar-io/thirt-party/lib/SDL2:$LD_LIBRARY_PATH" ./bin/main and got the following error: ./bin/main: error while loading shared libraries: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory

#

@ember yacht

#

wait i actually had a typo at the LD_LIBRARY_PATH command, i wrote thirt-party instead of third-party but when i run it again the right way i don t get any error,but the program won t start

#

no window no nothing

ember yacht
#

this time use ldd with the command like this LD_LIBRARY_PATH="/home/lucas/Programming/C++/Projects/Agar-io/third-party/lib/SDL2:$LD_LIBRARY_PATH" ldd ./bin/main

robust moss
robust moss
#

linux-vdso.so.1 (0x00007ffc0b914000)
libSDL2-2.0.so.0 => /home/lucas/Programming/C++/Projects/Agar-io/third-party/lib/SDL2/libSDL2-2.0.so.0 (0x00007fd77579e000)
libSDL2_image-2.0.so.0 => /home/lucas/Programming/C++/Projects/Agar-io/third-party/lib/SDL2/libSDL2_image-2.0.so.0 (0x00007fd775770000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd775400000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd77573b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd775000000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd775315000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd77599f000)

ember yacht
#

so now it finds the libs. it should run "without the ldd" unless the program is failing in a different way

robust moss
#

Hmm

#

I ll show you the code

#

main.cpp: // Main.cpp
#include "Game.h"

int main(int argc, char** argv) {
unsigned window_size[2] = {1400, 800};
Game game(window_size);
game.Run();
return 0;
}

#

Game.h:#pragma once

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <string>

class Game{
public:
Game(unsigned window_size[2]);
~Game();

void Run();
void Render();
void Update();
void DisplayFrameRate();
void CheckForEvents();

private:
bool isRunning = true;
unsigned window_size[2],startTime;
int frame_rate=0,camera_offset[2]={0,0};
SDL_Renderer* renderer;
SDL_Window* window;
SDL_Event event;
};

ember yacht
#

a windows will display showing framerate in the title, waiting for input to close. i can't SEE anything, but maybe someone else will find an error.

robust moss
#

Maybe i downloaded the libs in the wrong way

#

How do you recommend me to download them?

ember yacht
#

i would recommend do do a system download. if your distro doesnt have the version you need, then build them from source and install systemwide

#

i do something like this (if i need a newer version) ```bash
SDL2VER=2.30.0
curl -sLO https://libsdl.org/release/SDL2-${SDL2VER}.tar.gz
tar -xzf SDL2-${SDL2VER}.tar.gz
cd SDL2-${SDL2VER}
./configure
make && sudo make install
rm ../SDL2-${SDL2VER}.tar.gz