-
Notifications
You must be signed in to change notification settings - Fork 0
C API Export
Z User edited this page Mar 14, 2026
·
3 revisions
This guide explains how lp export generates a C-facing header, how --library extends that flow, which LP functions become part of the exported API, and which limitations still matter today.
- Read CLI and Tooling first.
- A working host C compiler is required if you use
--library.
lp export is aimed at interoperability with native C or C-compatible callers.
Current public workflow:
- parse an LP file
- generate a C API header
- optionally compile a shared library artifact
Generate a header:
lp export api.lp -o demo_apiResult:
demo_api.h
If -o is omitted, LP uses the LP file basename.
Generate both:
lp export api.lp --library -o demo_apiResult in the current implementation:
demo_api.hdemo_api.dll
The header generator walks top-level LP function definitions.
Current rules:
- top-level public functions are exported
-
privatetop-level functions are skipped - top-level function names starting with
_are skipped by convention - classes are not automatically turned into a documented stable C object API here
Exported symbols are prefixed with lp_.
If your LP function is:
def add(a: int, b: int) -> int:
return a + bThe generated declaration follows this pattern:
LP_EXTERN int64_t lp_add(int64_t lp_a, int64_t lp_b);def add(a: int, b: int) -> int:
return a + bGenerate the API:
lp export add.lp -o add_api
lp export add.lp --library -o add_api#include "add_api.h"
#include <stdio.h>
int main(void) {
printf("%lld\n", (long long)lp_add(20, 22));
return 0;
}- The generated header uses
__declspec(dllexport)on Windows and visibility attributes elsewhere. - The current library artifact naming is still
.dllin the implementation when--libraryis requested. - Parameters without explicit LP type annotations may degrade to less helpful C signatures in exported headers. For stable native interop, prefer explicit parameter and return annotations.
-
--libraryrequires a working host C compiler and the runtime include path. - The current implementation is oriented around C-callable top-level functions, not full class or object export.
- Shared-library naming is not yet normalized across Windows, Linux, and macOS.
- Experimental Python-interoperability paths are unrelated to
lp exportand are not a replacement for this stable header-generation path.
Back to Home | GitHub Repo | Issues
- Home
- Installation and Setup
- First Programs
- Language Basics
- Quick Reference
- Troubleshooting
- Known Limitations
- Language Reference
- Expressions and Collections
- Object-Oriented Programming
- Error Handling
- Feature Overview
- Feature Status
- Runtime Modules
- Concurrency and Parallelism
- Parallel and GPU Computing
- Security Overview
- Security Reference
- Security Calling Patterns
- Native ASM is the default backend.
- On Windows, prefer
--gccfor verification. - Docs are written against verified current behavior.