I’m a hobbyist level hack programmer but wanted to share the steps I followed to get Crystal working on Windows. I have MS Visual Studio 2022 installed with the C++ build tools.
BLUF: crystal runs, shards runs, libs get linked, things compile and run, woot.
The steps I followed were:
- install crystal windows preview via scoop
- compile and install Simple Directmedia Layer (SDL)–inclduing SDLMain–(Simple Directmedia Layer · GitHub) using Visual Studio 2022
- copy the SDL.lib and SDLmain.lib files to the crystal lib folder within scoop
- open Powershell and run crystal init app sdl_app
- cd sdl_app
- udpate shard.yml with
dependencies:
sdl:
github: ysbaddaden/sdl.cr - run shards install
- on error, open adminstrative powershell, and run shards udpate, close adminstrative powershell
- open windows environment variables within Windows Settings and add entry for CRYSTAL_PATH pointing to your scoop/apps/crystal/current/src;lib
- add require “SDL” to the source_file.cr
- run crystal build ./src/source_file should succeed
Note 1: sdl example files from the sdl shard should now be able to run once copied into the source_file.cr using crystal run ./src/source_file.cr
Note 2: to distribute the exe, it will require the SDL2.dll be in the same folder
crystal env shows the following
CRYSTAL_CACHE_DIR=C:\Users\me\AppData\Local\crystal\cache
CRYSTAL_PATH=lib;C:\Users\me\scoop\apps\crystal\current\src
CRYSTAL_VERSION=1.5.0
CRYSTAL_LIBRARY_PATH=C:\Users\me\scoop\apps\crystal\current\lib
CRYSTAL_OPTS=“”
***Updated based on Hadeweka’s suggestions.