This is an example/base/template application showing how its possible to code a portable application using containers.
- IDE: VSCode (
code) on Windows 11 w/clangdlanguage server - Compiler:
clang(build happens inside Container) - Compile Target: Podman Desktop > Podman Machine (WSL2) > Podman Container, running Alpine Linux
- Debugger:
lldbclient, connected to remotelldb-server(in Container)
Learn my particular approach to coding portable code in C99.
- Install LLVM v20.1.8 from llvm/llvm-project releases
- (bug workaround) Install specifically Python 3.10.10 Windows embeddable package (64-bit) by extracting it to
C:\Program Files (x86)\LLVM\bin.
- (bug workaround) Install specifically Python 3.10.10 Windows embeddable package (64-bit) by extracting it to
- VSCode Extensions
- Required
- ms-vscode.cpptools
- llvm-vs-code-extensions.vscode-clangd
- llvm-vs-code-extensions.lldb-dap
- Recommended
- GitHub.copilot
- GitHub.copilot-chat
- bierner.markdown-mermaid
- spmeesseman.vscode-taskexplorer
- ms-vscode-remote.remote-wsl
- Required
Use the VSCode launch.json launch configuration:
Debug main: main programDebug test: currently open unit test (ie.test/**/*.c)
The main trick here is we are cross-compiling from (any OS) to Linux using Clang.
Likewise, we are cross-debugging to Linux using LLDB.
-
LLDB client and server versions should match
-
You can automate the CLI by sending a chain of commands:
lldb -o "platform select remote-linux" -o "platform connect connect://localhost:2345"
-
Connecting the client manually:
# (probably unnecessary) disable ASLR in WSL2 podman machine settings set target.disable-aslr false target create build/main settings set target.source-map /app z:\tmp breakpoint set -f src/main.c -l 14 breakpoint clear -f src/main.c -l 14 process launch -
If you suspect the compiler is not emitting debug symbols correctly:
readelf -S build/main readelf --debug-dump=info build/main | grep DW_AT_name nm -a build/main