Yes, it is possible to use SDL2 without CMake. Here's a general approach:
Step 1: Download the SDL2 development libraries (not just the source code) for your platform from the SDLÂ website.
Step 2: Add the SDL2 include directory to your compiler's include path. For example, with g++:
g++ -I/path/to/SDL2/include ...
Step 3: Link against the SDL2 libraries when compiling. For example:
g++ ... -L/path/to/SDL2/lib -lSDL2 -lSDL2_image -lSDL2_ttf
Step 4: Make sure the SDL2 dynamic libraries are available at runtime, either by copying them to your executable's directory or adding their path to your system's library search path.
Here's an example of compiling a simple SDL2 program without CMake:
#include <SDL.h>
#include <iostream>
int main(int argc, char** argv) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
std::cout << "SDL_Init error: "
<< SDL_GetError() << "\n";
return 1;
}
std::cout << "SDL initialized successfully!";
SDL_Quit();
return 0;
}
SDL initialized successfully!
Compile with:
g++ -I/path/to/SDL2/include main.cpp -L/path/to/SDL2/lib -lSDL2 -o sdl_example
While this approach works, using a build system like CMake can make it easier to manage dependencies and build your project on different platforms.
Answers to questions are automatically generated and may not have been reviewed.
A step-by-step guide on setting up SDL2 and useful extensions in a project that uses CMake as its build system