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:
copy the SDL.lib and SDLmain.lib files to the crystal lib folder within scoop
open Powershell and run crystal init app sdl_app
udpate shard.yml with
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
Thanks for the suggestion, I’ve added the lib to the CRYSTAL_PATH and it doesn’t change the behavior of the require. Still needs the expanded line. My CRYSTAL_PATH is now “CRYSTAL_PATH=C:\Users\me\scoop\apps\crystal\current\src;CRYSTAL_PATH=C:\Users\me\scoop\apps\crystal\current\lib”. I’ll keep playing with it.
As to what I am doing, for years I’ve had a mental block regarding gui’s and I’ve decided now is the time to break that and get an understanding. Came across “SDL Game Development” and started going through the C++ code. From my time doing Ruby, I really hate the format and verbosity of C++, and am going to do the book exercises in both C++ and Crystal. Eventually, I’d like to do some modelling and sim using Crystal.
Ah, I see the problem, you seem to define CRYSTAL_PATH twice. Also, you just need to put lib into the variable, not the absolute path. This way, Crystal will always check for the local lib directory, regardless of your actual project.
Use the command set CRYSTAL_PATH=C:\Users\me\scoop\apps\crystal\current\src;lib
or directly set your environment variable to C:\Users\me\scoop\apps\crystal\current\src;lib
and it should work.
Also it definitely sounds interesting!
At one point I tried to build a game with C++, added Ruby scripting and then somehow ended up at Crystal instead.
I’m not fully settled on a media library yet (though it will probably be SDL in some way), but it’s already so much less frustrating than C++.