Playing with Crystal on Windows

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:

  1. install crystal windows preview via scoop
  2. compile and install Simple Directmedia Layer (SDL)–inclduing SDLMain–(Simple Directmedia Layer · GitHub) using Visual Studio 2022
  3. copy the SDL.lib and SDLmain.lib files to the crystal lib folder within scoop
  4. open Powershell and run crystal init app sdl_app
  5. cd sdl_app
  6. udpate shard.yml with
    dependencies:
    sdl:
    github: ysbaddaden/sdl.cr
  7. run shards install
  8. on error, open adminstrative powershell, and run shards udpate, close adminstrative powershell
  9. open windows environment variables within Windows Settings and add entry for CRYSTAL_PATH pointing to your scoop/apps/crystal/current/src;lib
  10. add require “SDL” to the source_file.cr
  11. 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.

8 Likes