- 1 year ago
SDL2 Msys2 Windows X64 build
To build SDL2 on Windows x64 using MSYS2, you can follow these steps:
Install MSYS2: Download and install MSYS2 from the official website (https://www.msys2.org/). Choose the 64-bit version if you're running Windows x64.
Update MSYS2: Open the MSYS2 MinGW 64-bit terminal (MSYS2 Mingw 64-bit) from the Start menu. Run the following command to update the package database and core packages:
bashpacman -Syu
If prompted to update the MSYS2 installation, close the terminal and reopen it.
Install Required Packages: Install the necessary packages required for building SDL2. Run the following command to install the required packages:
bashpacman -S base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-SDL2
Build SDL2: Create a build directory and navigate to it using the terminal. Run the following commands to configure and build SDL2:
bashmkdir build
cd build
cmake -G "MSYS Makefiles" ..
make
This will generate the Makefiles and build the SDL2 library.
Install SDL2: After the build process completes, run the following command to install SDL2:
bashmake install
This will copy the necessary files to the appropriate locations.
Verify Installation: You can verify the SDL2 installation by compiling and running a simple SDL2 program. Create a new C file with the following code:
c#include <SDL.h>
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("SDL2 Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
SDL_Delay(3000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
Save the file with a ".c" extension, and then compile and run it using the following commands:
bashgcc -o test test.c -lSDL2
./test
If everything is set up correctly, you should see a window titled "SDL2 Test" that remains open for 3 seconds before closing.
By following these steps, you should be able to build SDL2 on Windows x64 using MSYS2 and use it in your projects.