This guide helps AI assistants like Claude Code understand and work effectively with the llcppg project - a tool for automatically generating LLGo bindings for C/C++ libraries.
llcppg is a binding generator that bridges C/C++ libraries to LLGo (a Go-based compiler). It processes C/C++ header files and generates idiomatic Go bindings, enabling Go code to seamlessly interact with C/C++ libraries.
- llcppcfg - Configuration file generator (Go)
- llcppg - Main binding generator (Go)
- gogensig - Go signature generator (Go)
- llcppsymg - Symbol generator (LLGo, requires LLGo compilation)
- llcppsigfetch - Signature fetcher (LLGo, requires LLGo compilation)
cmd/- Main executables (llcppg, llcppcfg, gogensig)_xtool/- LLGo-compiled tools (llcppsymg, llcppsigfetch)cl/- Core conversion logic and AST processingparser/- C/C++ header file parsing interface. The core C AST to internal AST conversion logic is in_xtool/internal/parser, compiled with LLGoconfig/- Configuration file handling_llcppgtest/- Real-world binding examples (cjson, sqlite, lua, etc.)_demo/- Simple demonstration projects_cmptest/- Comparison and end-to-end tests
For detailed setup instructions including prerequisites, dependencies, and installation steps, see README.md.
go build -v ./...go test -v ./config ./internal/name ./internal/arg ./internal/unmarshalAlways run these unit tests first for quick validation before running the full test suite.
llgo test ./_xtool/internal/...
llgo test ./_xtool/llcppsigfetch/internal/...
llgo test ./_xtool/llcppsymg/internal/...go test -v ./...Some tests require LLGo tools installed via install.sh.
bash .github/workflows/test_demo.shALWAYS run before committing:
go fmt ./...
go vet ./...
go test -timeout=10m ./...The following components are built with LLGo and installed via bash ./install.sh:
- llcppsigfetch (
_xtool/llcppsigfetch/) — parses C/C++ headers into JSON AST - llcppsymg (
_xtool/llcppsymg/) — extracts symbols from C/C++ libraries
These tools share internal packages under _xtool/internal/ (e.g., parser, libclang, clangtool).
Tests such as TestFromTestdata (cl/internal/convert) invoke llcppsigfetch as a subprocess, so they depend on the installed binary being up to date.
When you modify any code under _xtool/ (including its internal dependencies), you MUST:
- Run
bash ./install.shto rebuild and reinstall the LLGo-compiled tools - Run the unit tests first to verify the modified packages work correctly, and check that any test output changes are expected (e.g.,
llgo test ./_xtool/internal/parser,llgo test ./_xtool/internal/header) - Run
go test -v ./cl/internal/convert -run TestFromTestdatato verify the dependent tests pass - If test output changes are expected, temporarily set
gen:truein the test to regenerate expected output (gogensig.expect), verify it is correct, then set back togen:false
For detailed technical specifications, see llcppg Design Documentation.
For complete details, see Type Mapping.
For complete details, see Name Mapping Rules.
For complete details, see Dependency.
For complete details, see File Generation Rules.
"llgo: command not found"
- LLGo not installed or not in PATH
- Solution: Install LLGo with correct commit hash
"llcppsymg: executable file not found"
- CRITICAL: MUST run
bash ./install.sh - This is absolutely essential for testing
"BitReader.h: No such file or directory"
- Install LLVM 19 development packages
- Ensure LLVM 19 is in PATH
Tests requiring llcppsigfetch or llcppsymg
- MUST install via
bash ./install.sh - Do not skip this step
Demo tests failing
- Verify library dependencies (libcjson-dev, etc.) are installed
Look at _llcppgtest/ subdirectories for working configurations:
cjson/- JSON library bindingsqlite/- Database bindinglua/- Scripting language bindingzlib/- Compression library bindinglibxml2/- XML parsing with dependencies
Each contains:
llcppg.cfg- Configuration- Generated
.gofiles demo/- Usage examples
When adding a new feature to llcppg, follow this workflow to verify your changes:
-
Create a test case in
cl/internal/convert/_testdata/with:- A
conf/directory containingllcppg.cfgandllcppg.symb.json - An
hfile/directory with your test header files - Configuration that exercises your new feature
- A
-
Generate the expected output using the
testFromfunction:- Temporarily set
gen:truein the test call to generategogensig.expect - Run the test:
go test -v ./cl/internal/convert -run TestFromTestdata - This creates the expected output file that future test runs will compare against
- Temporarily set
-
Verify the test passes with
gen:false:- Change back to
gen:false(or remove the gen parameter) - Run the test again to ensure it passes
- The test compares generated output against
gogensig.expect
- Change back to
-
Do NOT commit the test case to the repository unless it's a permanent regression test
- Use test cases for verification during development
- Only add to
_testdata/if it should be part of the test suite
Example test structure:
cl/internal/convert/_testdata/yourfeature/
├── conf/
│ ├── llcppg.cfg
│ └── llcppg.symb.json
├── hfile/
│ └── test.h
└── gogensig.expect (generated with gen:true)
For detailed version requirements and installation instructions, see README.md.
Header files in include must be in dependency order. If filter.h uses types from vli.h, then vli.h must appear first in the include array.
- Use JSON format for
llcppg.cfg - Follow examples in
_llcppgtest/for structure - Comment complex configurations
- Do not manually edit generated
.gofiles - Regenerate bindings after config changes
- Use
typeMapandsymMapfor customization
- Add test cases for new features
- Run full test suite before PR
- Validate with real library examples
The project uses GitHub Actions workflows:
.github/workflows/go.yml- Main test suite.github/workflows/end2end.yml- End-to-end validation.github/workflows/test_demo.sh- Demo validation script
These run automatically on PR and provide validation feedback.
- Check README.md for comprehensive usage documentation
- Review design documentation in
doc/en/dev/ - Study working examples in
_llcppgtest/
- Always install tools first - Run
bash ./install.shbefore testing - Follow dependency order - LLGo requires specific LLVM and commit versions
- Validate thoroughly - Run full test suite and demos
- Study examples - Real-world bindings in
_llcppgtest/are the best reference
This guide provides the foundation for working effectively with llcppg. For detailed technical specifications, always reference the design documentation in doc/en/dev/.