Cannot find -lSDL2


#1

Untarred the source code and compiled it on a folder on my desktop: https://www.libsdl.org/release/SDL2-2.0.5.tar.gz

Makefile:

OBJS specifies which files to compile as part of the project
OBJS = hello.cpp

#CC specifies which compiler we're using
CC = g++

#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
COMPILER_FLAGS = -w -I/home/me/Desktop/SDL/SDL2-2.0.5/include

#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -lSDL2main -lSDL2

#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = hello

#This is the target that compiles our executable
all : $(OBJS)
        $(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)

I’m guessing I need to tell the compiler where to look for the libraries but I have no idea where it could be. There’s no lib folder in the SDL2-2.0.5 folder?


#2

If you built it with make in the root directory of the source, you should find it at /home/me/Desktop/SDL/SDL2-2.0.5/build/.libs. If you used CMake, it should be in that directory where you built it.

If you don’t install the library into the default library search paths, you can use the -L option to tell g++ where to look: -L/home/me/Desktop/SDL/SDL2-2.0.5/build/.libs. You also need to tell the dynamic linker where to look with the LD_LIBRARY_PATH environment variable:

export LD_LIBRARY_PATH=/home/me/Desktop/SDL/SDL2-2.0.5/build/.libs
./hello

Check with ldd if it got picked up correctly.

ldd ./hello

This will print the library paths it will use for your program.