I'm using c++ to develop (and by extension, C), and I am attempting to add FLECS library to the game. Well, FLECS isn't exactly designed for embedded but I somehow was able to compile it after changing/removing some modules, however the resulting dll simply causes "LoadLibraryA() failed", and I have no clue what would be the cause... Can anyone provide some insight?
FLECS does attempt to include some system headers that might not be available on playdate, but that's just my guess.
Ah so the number was an error code then! Didn't realise that. It's 126 so the library is expecting some system/os dll I suppose. Whelp, it was FLECS having both STATIC and SHARED flags turned on for some reason and end up requiring to link against flecs.dll while that dll was never produced.
Hmm, despite being able to run in the simulator now, the game would instantly crash on the real device... This time I really don't have any debug info.
Here are the possibly problematic includes in the library, any of them I should remove?
stdio.h
stddef.h
ctype.h
time.h
assert.h
stdarg.h
string.h
stdint.h
stdbool.h
stdlib.h
math.h
errno.h
Or perhaps its printf and stdout? (literally dumping my suspicion)
It sounds like you still have some linking issues; standard lib doesn't exist on device while it exists on the host computer so it will look like code is building correctly but in reality it isn't. There are posts around here that talk about how to resolve these types of issues.
You can't use stdio.h, time.h, or errno.h on the Playdate device since it doesn't have a libc to link against. You'll have to use the PlaydateAPI struct pointer to write replacements for the functions you need.
Oh! Also, pthread doesn't exist on device since all C code (except callbacks) runs in the same FreeRTOS task.
Example: playdate->system->logToConsole is basically a drop-in replacement for printf.
Update: after fiddling with the code for days I still can't make it run on the device. I've removed every time.h, errno.h, stdio.h and most of the stdlib.h as suggested, and replaced them with corresponding playdate API... No luck. Dependency checker doesn't help either.
I didn't removed all the stdio functions because... some of them does work? like atoll, memcpy, memset. So I'm really in the dark now. Oh well, now I have removed all of the #include <stdlib.h> from the library and it still crashes. I'm out of clue
Do you have a crashlog.txt file in the device data disk? If so, you might want to consider posting it here for someone to take a look at. It'll give a bit of info about where the crash occurred.
However, I encountered a peculiar issue when trying to identify which part of the flecs_bootstrap caused an issue. I tried to use goto to skip parts of the code but eventually it turned out... that it didn't work.
The following will still crash the system despite it should do nothing except for a jump:
void flecs_bootstrap(ecs_world_t* world){
return;
//... rest of the function body
}
In contrast, the following will not crash the system (the whole function body deleted and replaced with just a return;) :