SDL static compillation

Hello! I want to compile my project with SDL2, SDL2_image, SDL2_ttf, SDL2_mixer, but I cant find how to create cmake file for it. Ive been searching for it for a really long time. Please help me!

create cmake file for it

What is “it” in here? :slight_smile:

You need help with creating an entire project file from scratch? Then I’d recommend starting with some tutorials:
If you already have at least a draft of your project file, then share it and describe the problems you have.

Or do you need help with building SDL from sources? In that case, it already has CMakeLists.txt, so you shouldn’t need to do anything special for that. Do you have some specific issues with it?

I set the direct path to the folders, but at the result the binary file asks the libs from the /usr/lib. Idk why…

How do you set that path and what folders do you mean? It would be useful to see at least this particular fragment from your project file.

please look. I paste an sdl folder with .so libs to the project and after that I try to cmake it. Sorry for 3 days gap

i have .so in the sdl folder because I dont know how to staticly compile it. So I try to keep libs in the project

I see, so you don’t use CMake configs for discovering SDL. In that case you first need to “find” the SDL binaries with find_library(), and only then you will be able to link to it with target_link_libraries(). And you will most likely also need to add SDL headers to your project’s include directories. So an example would look like this:

set(SDL_PREFIX "/path/to/sdl/installation") # can be set via CLI with -D
find_library(sdl SDL2 PATHS "${SDL_PREFIX}/lib") # SDL2_image SDL2_ttf SDL2_mixer ...
        sdl # SDL2_image SDL2_ttf SDL2_mixer ...

But I would recommend you to use CMake configs provided by SDL - in that case you’ll only need to use find_package(), for example:

# it is assumed that path to SDL installation is added to CMAKE_PREFIX_PATH
find_package(SDL2 CONFIG REQUIRED)

I dont know how to staticly compile it

How did you try to compile it? Not setting BUILD_SHARED_LIBS or explicitly setting it to 0 should be enough. Or are you not using CMake to build SDL?

I have in the sdl subfolder. I want my programm to get the dependencies from this folder. Not from /usr/lib. How can I generate Makefile by cmake that will compile it for me?

structure of the project:

set(SDL_PREFIX "/path/to/sdl/installation")

Quite obviously, you need to replace that path with yours.