C template / setup on Windows 2023

I'd like to give it a try to develop for the playdate with C. But being a C noob, I struggle with even getting a basic hello world in main.c running (..PlaydateSDK\C_API\Examples\Hello World)

I've followed along the documentation and gave it a try with Clion:

But clion doesn't seem to know the "platform", I've got the error:
CMake Error at C:/Users/haas/Documents/PlaydateSDK/C_API/buildsupport/playdate_game.cmake:68 (message):
Platform not supported!
And I could solved the last part with adding the path to the simulator, I didn't understand where to add it.

I could run the cmake to build without errors throught the "x64 Native Tools Command Prompt for VS 2019" and open it with the visual studio 2019:

When opened in visual studio and trying to run it (default run config: Debug, x64 and "local windows debugger") I'm getting an access denied error.

Do I need to create a run config for the playdate simluator?

I've had a look at the old thread:

At the end says, one should use the Inside Playdate with C for setup. But I lack the pre-required knowledge.

So yeah, it would be great to have a beginner friendly guide to setup the playdate to code with C (on Windows).

Also here are some templates (which I couldn't get any to run :slight_smile: ):
https://github.com/MattouBatou/playdate-c-game-template/tree/main

CMake + CLion on Windows isn't officially supported at the moment, however you probably could get it working with a bit of work. What complier do you have CLion pointing at? If you are getting a platform not supported error from the CMake file it's not using MSVC to compile so the correct flags aren't be set from CLion when running the CMake file. Unfortunately I don't know CLion so I'm not much help when it comes to configuring it.

As for Visual Studio 2019, that should work without issue. Where did you install the SDK? Are you running as an Admin user? Without the exact error code it's hard to debug it from here, but I'd suggest googling around a bit for the error. My guess is you'll find someone with the same issue.

The Debug and Release configs already have the Simulator targeted, there is no need for additional configuring.

I personally haven't used any of these C GitHub projects so I'm not sure what sort of state they are in. I'd stick with getting the examples working first with the steps listed in Inside Playdate with C, then start looking at other people's projects.

The sdk_path is set correctly.
Okay, about the Visual Studio 2019. If I load up the generated project from the build folder, should the run config say something like "playdate simulator"?

Because it just says "local windows debuger" ... how to I link it with the playdate simulator?

Local Windows Debugger is correct. You'll be doing your debugging in Visual Studio, not the Simulator. The example projects are set up to launch and run the built game the Simulator and debug it in VS.

That said, in the Solutions Explorer make sure "hello_world" (or whatever your project is called) is "Set as Startup Project" using the right-click menu. Then when you click the "Local Windows Debugger" button it will launch the Simulator and automatically start debugging the current source code.

I hope that helps a bit.

1 Like

I was not able to build C project at all on Windows. Tried with visual studio code, visual studio, Clion and using command cmake and make.
Im total newbie with C programming and compilation.

Finally, after days of trial and error, I've managed to build it on WSL with Ubuntu.
I'm building it using make.
Project built on Linux doesn't work on Windows simulator. So you also have to start simulator from WSL.
Currently it's the only way that I'm able to work on Lua project with C library added (box2d)

2 Likes

on discord i explained how i do it for one person so i'm pasting it here also it might help you to get it going

  1. Download visual studio 2022 community edition & install it
  2. Download cmake from here Download CMake (use the zip version)
  3. Download arm-gnu-toolchain-12.3.rel1-mingw-w64-i686-arm-none-eabi.zip (take latest version if newer) from https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
  4. extract cmake and the arm gnu tool chain somewhere for example in c:\playdate (i have my playdatesdk in c:\playdate\playdatesdk and in c:\playdate i also have cmake and the arm toolchain
  5. for any new project you want to start, copy PlaydateSDK\C_API\Examples\Hello World to a new folder
  6. Edit CMakeList and change these 2 lines to your game name set(PLAYDATE_GAME_NAME hello_world) set(PLAYDATE_GAME_DEVICE hello_world_DEVICE) the part you need to change is "hello_world"
  7. save this as a playdateenvironment.bat (not playdateenvironment.bat.txt !!!) somewhere and adapt the paths to your environment / install
SET PLAYDATE_SDK_PATH=C:\playdate\PlaydateSDK
SET PATH=C:\playdate\gcc-arm-11.2-2022.02-mingw-w64-i686-arm-none-eabi\bin;C:\playdate\CMAKE\bin;%PATH%
%comspec% /k  "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
  1. double click the playdatenvironment.bat file and it will open a cmd prompt
  2. "cd" to your directory that contains your (renamed) copy of "Hello World" c api example
  3. inside that directory create 2 new subdirs (can use mkdir command) named build_device and build_simulator
  4. first cd in the build_simulator directory and now type cmake .. (.. referes to previous / one dir up and in that one dir up the cmakelists file should exist). This will generate solution files which you can open in visual studio 2022, once you open them set the middle project (the game itself) as startup project rebuild the solution & press the run / play button. You have the game now working for simulator. if you want to add new .c or .h files add them to the src directory where main.c is and drag them to the solution explorer in visual studio, don't use file-> new in visual studio as it will save the files in build_simulator directory which is wrong or erase build_simulator after adding the .c .h files to correct directories and restart the cmake .. command to regenerate the solution files. normally you only need todo this once to generate the solution files and you can continue working with visual studio 2022
  5. to compile for the playdate device itself cd build_device
  6. run cmake .. -G "NMake Makefiles" --toolchain=<path to SDK>/C_API/buildsupport/arm.cmake adapt <path to sdk> in this command to where your playdate sdk is installed and verify you target the arm.cmake file correctly.
  7. now you can run nmake command to build for the playdate if you want to recompile or so do nmake clean followed by nmake again
  8. building optimized Release version for playdate cd to build_device again when having done the above cmake command at least once then type cmake -DCMAKE_BUILD_TYPE=Release .. this will change the build target to release and will compile your game with -O3 etc optimizations level

in all cases your build files will be in NameOfGame.pdx directory and you should always put your sources in src dir and your assets in Source dir. If you want to use subfolders to add source codes under src. you need to modify cmakelist.txt and add a multiple source lines for example like so :

file(GLOB SOURCES
    "src/*.c"
    "src/gameobjects/*.c"
    "src/gamestates/*.c"
)

you can see an example of this in the edited default cmakelist i use to make it find all C files easier here is an example : https://github.com/joyrider3774/formula1_playdate/blob/main/CMakeLists.txt

4 Likes

if you gotten that far, the solution should load 3 projects, but by default the wrong project is setup as start up project. You need to set the middle (2nd) project in the solution as start up project, then you can just press the "play" button to make it compile and run it inside the simulator (be aware the very first time you run the simulator it won't work and you need todo this a second time, but this is only when you really just installed the simulator and run it for the first time)

1 Like

After some hours of trying and failing, I finally got building for the local Simulator and the Playdate hardware to work on Windows 10 with Visual Studio 2019 and CMake.
Here are some pitfalls I encountered. Hopefully these tips are helpful for other people having trouble.
I tried to follow the main guide as much as possible.

Make sure you have no spaces in your paths!
This includes the PlaydateSDK installation folder and CMake folder - and probably arm-gcc folder. (Spaces in the project name and build folder seem to be okay, since the "Hello World" project builds and runs fine)
Be very careful about the default installation folder of the PlaydateSDK. As it is your Documents folder, this will lead to problems if your username is "Jane Doe" or any other string with a space.

If you are going the make/Makefile route, this will simply not work: shell - Can GNU make handle filenames with spaces? - Stack Overflow

Using a Hardlink (mklink /J) will not help!
You might be able to build your app fine, but when running in the simulator you might get weird errors with an empty loading failed box and "Load failed, error: (null)" and "Update error: no such function 'update'" in the console:
Imgur

I really think this is worthy of a note in the official documentation.

Do not install Playdate SDK to Program Files!
Same reason as above, but also this will lead to all sorts of problems due to missing permissions. The Simulator will not even be able to load the default Settings.pdx
Imgur

So to get it working I basically just followed section 5 of the main guide: Inside Playdate with C
(on that note, I feel like the structure of the guide is really weird, since section 3, 4 and 5 are basically alternatives to each other, yet in section 3 it reads like Visual Studio is not on the list of supported IDEs, so I almost stopped there)

However I went the same route as joyrider3774 and created a "C:\Playdate" directory, where I put CMake, ARM-GCC and the SDK. For CMake and ARM-GCC I just downloaded the zip packages, extracted them and added those folders to path manually. This works wonderfully so far. (but you can probably also use the installers, just make sure to target the C:\Playdate directory)
So in the end the setup looks like this:
Imgur
PATH user variable (if you don't want to add it permanently, just follow joyrider3774's guide and use the bat file):
Imgur
PLAYDATE_SDK_PATH
Imgur

As a quick tip, if you want to call CMake for the Playdate build. You can just use this (since the environment variable should be set anyway):

cmake .. -G "NMake Makefiles" --toolchain=%PLAYDATE_SDK_PATH%/C_API/buildsupport/arm.cmake

Hope this helps!

2 Likes

Adding to my previous post: I created a batch script to streamline the initial CMake setup on new projects:

Might turn this into a full setup / build script eventually as I go along.

1 Like