# Playing with Crystal on Windows

**URL:** <https://forum.crystal-lang.org/t/playing-with-crystal-on-windows/4877>\
**Category:** Learning Resources\
**Created:** [August 23, 2022, 11:23pm UTC](https://forum.crystal-lang.org/t/playing-with-crystal-on-windows/4877 "2022-08-23T23:23:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robmullr](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/robmullr/32/1113_2.png) [@robmullr](https://forum.crystal-lang.org/u/robmullr)\
**Post date:** [August 23, 2022, 11:23pm UTC](https://forum.crystal-lang.org/t/playing-with-crystal-on-windows/4877/1 "2022-08-23T23:23:55Z")

</div>

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](https://github.com/libsdl-org)) 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.

---

<div class="post-metadata">

**Author:** ![Hadeweka](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hadeweka/32/1332_2.png) [@Hadeweka](https://forum.crystal-lang.org/u/Hadeweka)\
**Post date:** [August 24, 2022, 9:16am UTC](https://forum.crystal-lang.org/t/playing-with-crystal-on-windows/4877/2 "2022-08-24T09:16:27Z")

</div>

Small note: If you set `CRYSTAL_PATH` to `lib` as well, it should suffice to simply do `require "sdl"`, to make the code a bit more portable 🙂

If I may ask: Do you have something specific in mind you want to do with Crystal and SDL?

---

<div class="post-metadata">

**Author:** ![robmullr](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/robmullr/32/1113_2.png) [@robmullr](https://forum.crystal-lang.org/u/robmullr)\
**Post date:** [August 24, 2022, 1:01pm UTC](https://forum.crystal-lang.org/t/playing-with-crystal-on-windows/4877/3 "2022-08-24T13:01:24Z")

</div>

> [@robmullr](#):
>
> …/lib/sdl/src/sdl.cr

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.

---

<div class="post-metadata">

**Author:** ![Hadeweka](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hadeweka/32/1332_2.png) [@Hadeweka](https://forum.crystal-lang.org/u/Hadeweka)\
**Post date:** [August 24, 2022, 2:51pm UTC](https://forum.crystal-lang.org/t/playing-with-crystal-on-windows/4877/4 "2022-08-24T14:51:08Z")

</div>

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++.

---

<div class="post-metadata">

**Author:** ![robmullr](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/robmullr/32/1113_2.png) [@robmullr](https://forum.crystal-lang.org/u/robmullr)\
**Post date:** [August 24, 2022, 4:23pm UTC](https://forum.crystal-lang.org/t/playing-with-crystal-on-windows/4877/5 "2022-08-24T16:23:31Z")

</div>

Thanks, appreciate the hint on lib;. Now works as I’d expect and I’ve updated the original post.

---

<div class="post-metadata">

**Author:** ![Bonarc](https://avatars.discourse-cdn.com/v4/letter/b/7ab992/32.png) [@Bonarc](https://forum.crystal-lang.org/u/Bonarc)\
**Post date:** [May 28, 2024, 12:53am UTC](https://forum.crystal-lang.org/t/playing-with-crystal-on-windows/4877/6 "2024-05-28T00:53:49Z")

</div>

Thanks, this worked for me too
