Hello world: segfault in pdc on mac in vs code

I am attempting to build the C hello world project in VS Code on Mac. I have configured the cmake build to the point it calls pdc to compile the results of the build from the Source folder into the pdx. pdc crashes with a segfault 11:

[main] Building folder: Playdate-C-Hello-World 
[build] Starting build
[proc] Executing command: /Applications/CMake.app/Contents/bin/cmake --build /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/build --config Debug --target all -j 10 --
[build] /Applications/CMake.app/Contents/bin/cmake -S/Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World -B/Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/build --check-build-system CMakeFiles/Makefile.cmake 0
[build] /Applications/CMake.app/Contents/bin/cmake -E cmake_progress_start /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/build/CMakeFiles /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/build//CMakeFiles/progress.marks
[build] /Applications/Xcode.app/Contents/Developer/usr/bin/make  -f CMakeFiles/Makefile2 all
[build] /Applications/Xcode.app/Contents/Developer/usr/bin/make  -f CMakeFiles/c_template_DEVICE.dir/build.make CMakeFiles/c_template_DEVICE.dir/depend
[build] cd /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/build && /Applications/CMake.app/Contents/bin/cmake -E cmake_depends "Unix Makefiles" /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/build /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/build /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/build/CMakeFiles/c_template_DEVICE.dir/DependInfo.cmake --color=
[build] Consolidate compiler generated dependencies of target c_template_DEVICE
[build] /Applications/Xcode.app/Contents/Developer/usr/bin/make  -f CMakeFiles/c_template_DEVICE.dir/build.make CMakeFiles/c_template_DEVICE.dir/build
[build] [ 33%] Building C object CMakeFiles/c_template_DEVICE.dir/src/main.c.obj
[build] /Applications/gcc-arm/bin/arm-none-eabi-gcc -DTARGET_EXTENSION=1 -DTARGET_PLAYDATE=1 -I/Users/psychicteeth/Developer/PlaydateSDK/C_API -Wall -Wno-unknown-pragmas -Wdouble-promotion -O2 -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -D__FPU_USED=1 -falign-functions=16 -fomit-frame-pointer -gdwarf-2 -fverbose-asm -ffunction-sections -fdata-sections -mword-relocations -fno-common -std=gnu11 -MD -MT CMakeFiles/c_template_DEVICE.dir/src/main.c.obj -MF CMakeFiles/c_template_DEVICE.dir/src/main.c.obj.d -o CMakeFiles/c_template_DEVICE.dir/src/main.c.obj -c /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/src/main.c
[build] [ 66%] Linking C executable c_template_DEVICE.elf
[build] /Applications/CMake.app/Contents/bin/cmake -E cmake_link_script CMakeFiles/c_template_DEVICE.dir/link.txt --verbose=1
[build] /Applications/gcc-arm/bin/arm-none-eabi-gcc -nostartfiles -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -D__FPU_USED=1 -T/Users/psychicteeth/Developer/PlaydateSDK/C_API/buildsupport/link_map.ld -Wl,-Map=game.map,--cref,--gc-sections,--no-warn-mismatch,--emit-relocs --entry eventHandlerShim CMakeFiles/c_template_DEVICE.dir/Users/psychicteeth/Developer/PlaydateSDK/C_API/buildsupport/setup.c.obj CMakeFiles/c_template_DEVICE.dir/src/main.c.obj -o c_template_DEVICE.elf 
[build] /Applications/gcc-arm/bin/arm-none-eabi-strip --strip-unneeded -R .comment -g c_template_DEVICE.elf -o /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/Source/pdex.elf
[build] cd /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World && /Users/psychicteeth/Developer/PlaydateSDK/bin/pdc -sdkpath /Users/psychicteeth/Developer/PlaydateSDK Source c_template.pdx
[build] /bin/sh: line 1: 78696 Segmentation fault: 11  /Users/psychicteeth/Developer/PlaydateSDK/bin/pdc -sdkpath /Users/psychicteeth/Developer/PlaydateSDK Source c_template.pdx
[build] make[2]: *** [c_template_DEVICE.elf] Error 139
[build] make[2]: *** Deleting file `c_template_DEVICE.elf'
[build] make[1]: *** [CMakeFiles/c_template_DEVICE.dir/all] Error 2
[build] make: *** [all] Error 2
[proc] The command: /Applications/CMake.app/Contents/bin/cmake --build /Users/psychicteeth/Documents/GitHub/Playdate-C-Hello-World/build --config Debug --target all -j 10 -- exited with code: 2
[driver] Build completed: 00:00:00.460
[build] Build finished with exit code 2

I have uploaded the repository here GitHub - psychicteeth/Playdate-C-Hello-World: An empty playdate C/Lua project that can be built in VS Code on Winodws and Mac.

I'd be interested to hear if others get the same crash.

I've messed around with the c file but nothing I change about it seems to fix the crash.

Ok, I was not able to determine the actual cause of this segfault, beyond "Just not using make correctly" - sometimes it worked if I used "make pdc" and obviously it works fine if I just use the out of the box Hello World example and stock cmake files.

I have redone this repository to use nmake for Windows and make for MacOS just like it says in Inside Playdate with C, so this is no longer an issue, though it does seem like there could be better error reporting from pdc when it's fed some duff libraries.

1 Like

I'm having the same issue here, although admittedly I am in a different situation than OP. I modified the ldscript to have the entrypoint point to _start instead of eventHandlerShim. Could that be the problem? Any suggestion on how to debug this? it looks like pdc was not compiled with the debugging entitlement.

OPs issue was because there is a bug with pdc and 10.15. They had to download the prior version of the SDK which works with macOS 10.15.

1 Like

As Will says - if you use pdc from SDK 2.0.3 you may have luck <3

@AlexMay Could you try the 2.2 SDK and let me know if this is fixed? Thanks!

1 Like

Yep that's working Will! Thank you very much!
(edit: to test this I first reinstalled 2.1.0 and confirmed that compiling my project resulted in the segfault. Then I installed 2.2.0 and compiled again, without the segfault occurring)