Help create a static library that includes all dependencies

I'm making a game with the C api that runs fine in the Mac and Linux simulators but won't load in the Windows simulator.

The problem

The error that the windows sim spits out is:

$ echo $PATH
$ ./PlaydateSimulator.exe
# [output removed; everything runs fine, the game can be loaded]

# remove mingw build tools from the PATH to simulate a regular user's environment 
$ export PATH=/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perlin/vendor_perl:/usr/bin/core_perl

# try again. This time, loading the game fails
$ ./PlaydateSimulator.exe
11:27:42: SDK: C:\Users\ninov\Documents\PlaydateSDK
11:27:42: Release: 2.5.0
11:27:42: Loading: C:\Users\ninov\codeProjects\wheelsprung\wheelsprung.pdx\
Loading C API game: C:/Users/ninov/codeProjects/wheelsprung/wheelsprung.pdx/pdex.dll
LoadLibraryA() failed: (126): C:/Users/ninov/codeProjects/wheelsprung/wheelsprung.pdx/pdex.dll
11:27:42: Loading: OK
Update error: Could not load the Library.
11:27:42: Update failed, simulator paused.

Conclusion: pdex.dll seems to dynamically link to some dll in the mingw distribution.

From a discussion in the Playdate Squad Discord it seems to specifically be libgcc_s_seh-1.dll and libwinpthread-1.dll from the mingw distribution that seems required.

My game is open source and can be found here: GitHub - ninovanhooff/wheelsprung

Note the libs/windows/libchipmunk.a which I suspect is the problem.

How I built the libchipmunk.a library

Repo available here: GitHub - ninovanhooff/chipmunk-2d: A fast and lightweight 2D game physics library with added Playdate support.

  • Install Msys2 Mingw64 Environments - MSYS2
  • install cmake, ninja and make
    pacman -S mingw-w64-x86_64-make
    pacman -S mingw-w64-x86_64-cmake
    pacman -S mingw-w64-x86_64-ninja
  • create makefiles and build
    ninoLocal@NINO-WIN10 MINGW64 /c/Users/ninov/codeProjects/playdate-chipmunk-2d-master/build
    -- Building for: Ninja
    -- The C compiler identification is GNU 13.2.0
    -- The CXX compiler identification is GNU 13.2.0
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    Configuring Chipmunk2D version 7.0.3
    -- SDK Path: C:\Users\ninov\Documents\PlaydateSDK\
    -- Configuring done (3.6s)
    -- Generating done (0.0s)
    -- Build files have been written to: C:/Users/ninov/codeProjects/playdate-chipmunk-2d-master/build
    $ ninja
    [.. no issues ..]
    [34/34] Linking C static library src\libchipmunk.a
  • Add libchipmunk.a to my Nim game and create a pdx
  • Find issue described above

What I tried

It has been suggested that -static should be passed to CFLAGS so that all dependencies will be included. I tried this in several ways:

  • export CFLAGS=-static and rerun cmake + ninja
  • add the following to CMakeLists.txt:
  • instead of ninja, use -G "MinGW Makefiles" for cmake and mingw32-make to make. I was told even for 64 bit the command should be mingw32-make.

These approaches seemed to result in rougly the same file, all with the same size of 843KB.

To be honest, I doubt, whether adding this flag was successful.

What I'm hoping to achieve

I would like to produce a pdx file that "just works" on windows 64 bit. I do not care too much about file size. If all mingw dlls would be included, that would be acceptable.

Any tips?

1 Like

A first step might be to verify whether adding the -static flag was successful as I doubt that.

cmake documentation seems to have a relevant warning: add_link_options — CMake 3.30.0 Documentation

This command cannot be used to add options for static library targets, since they do not use a linker. To add archiver or MSVC librarian flags, see the STATIC_LIBRARY_OPTIONS target property.

I guess I need more handholding to figure out how to set those static options tho...

I would call this a workaround rather than a solution, but I did finally manage to produce a working windows build by using tdm-gcc

Another interesting suggestion I got is to try building a release build rather than a debug build, because perhaps te release build doesn't require the extra libs.