w64devkit Documentation

repository·master·Indexed 26 days ago

https://github.com/skeeto/w64devkit

A portable, small-footprint C, C++, and Fortran development suite for x86 and x64 Windows. It provides a statically-linked toolchain including GCC, GDB, Make, CMake, and Unix-like utilities via BusyBox. Features include specialized libraries like libmemory and libchkstk, C11 threading support via threads.h, and unique command-line tools such as peports, vc++filt, and debugbreak.

Tokens
1K
Snippets
2
Records
9
Agent score
39%

What's inside w64devkit

  1. Enable transparent build caching with Ccache

    master

    You can automatically cache all builds by prepending the Ccache directory to your PATH. Alternatively, you can call ccache, ccache-gcc, or ccache-g++ directly. You can also activate a suggested configuration via w64devkit.ini.

    PATH="$W64DEVKIT_HOME/lib/ccache;$PATH"
  2. Build w64devkit from source using Docker

    master

    To build the development kit from source, use Docker to build the image and then run it to produce a self-extracting 7z archive.

    Note: Do not use PowerShell for this process as it lacks the necessary file redirection capabilities.

    docker build -t w64devkit .
    docker run --rm w64devkit >w64devkit-x64.exe
  3. Use w64devkit in a Windows environment

    master

    The kit is distributed as a self-extracting 7z archive. You can use it in two ways:

    1. Interactive Console: Extract the archive and run w64devkit.exe. This launches a console window with a pre-configured environment and sets W64DEVKIT_HOME (installation root) and W64DEVKIT (version) environment variables.
    2. Manual Path Integration: Add the bin directory to your system PATH to use the tools in existing shells like cmd.exe or batch scripts.

    To start an interactive Unix-like shell after updating the PATH, run sh -l.

  4. Install additional libraries in w64devkit

    master

    Since w64devkit only includes standard libraries and Win32 import libraries, you can install third-party libraries using one of these three methods:

    1. Sysroot Installation: Install directly into the w64devkit directory (e.g., lib/, include/). This is the easiest method but requires re-installation after upgrading w64devkit. If the library has .pc files, pkg-config will find them automatically.
    2. Environment Variables: Append the library's installation directory to your CPATH and LIBRARY_PATH environment variables (use ; as a delimiter).
    3. Pkg-config Integration: Append the library's pkgconfig directory to the PKG_CONFIG_PATH environment variable (use ; as a delimiter).
  5. Use unsupported w64devkit enhancements

    master

    The contrib/ directory contains instructions for manually adding third-party libraries (such as garbage collection or POSIX regex.h) to your w64devkit environment. These enhancements are not included in the standard distribution.

    To use an enhancement:

    1. Navigate to the specific file in contrib/ for the library you want.
    2. Read the header of that file for specific usage instructions.
    3. Obtain the library source code independently.
    4. Use the custom build script provided in the contrib/ file to build and integrate the library into your environment.
  6. Use Undefined Behavior Sanitizer (UBSan) with GDB

    master

    While Address Sanitizer (ASan) and Thread Sanitizer (TSan) are not ported to Mingw-w64, Undefined Behavior Sanitizer (UBSan) works with GDB. To have GDB break precisely on undefined behavior without needing to link libsanitizer, use the following flags:

    -fsanitize=undefined -fsanitize-trap
  7. Use C11 threading with threads.h

    master

    The toolchain includes the C standard header threads.h with a fast, lean implementation.

    Constraints:

    • Requires Windows Vista or later.
    • Does not implement recursive or timed locks.
    • thrd_current returns a dummy handle useful only for thrd_equal. Using this handle to join or detach will cause a trap.
    • mtx_t and cnd_t support zero-initialization; their destructors are no-ops (similar to MSVC).
  8. Reference unique w64devkit command-line tools

    master

    The following specialized utilities are included in the kit:

    • peports: Displays export and import tables of EXEs and DLLs (similar to MSVC dumpbin /exports and /imports).
    • vc++filt: A name demangler for Visual C++ decorations, useful for examining GCC-incompatible binaries.
    • debugbreak: Causes all debugee processes to break in the debugger (similar to the Windows F12 hotkey).
  9. Link specialized libraries: libmemory and libchkstk

    master

    w64devkit provides two unique libraries for specific low-level needs:

    • libmemory.a: Provides memset, memcpy, memmove, memcmp, and strlen implemented as x86 string instructions. Link with -lmemory when not linking a CRT to provide tiny definitions required by GCC.
    • libchkstk.a: Provides a leaner, faster definition of ___chkstk_ms and __chkstk. Link with -lchkstk during -nostdlib builds, especially when linking MSVC artifacts.