jac-native-shared

Builds C-ABI shared libraries from Jac code using jac nacompile --shared.

Updated Jul 26, 2026
One-click install
npx skills add https://github.com/PMN123/trapdoor --skill jac-native-shared-pmn123
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jac-native-shared
Source: https://github.com/PMN123/trapdoor/tree/main/.agents/skills/jac-native-shared
Command: npx skills add https://github.com/PMN123/trapdoor --skill jac-native-shared-pmn123

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Exposing Jac code to other languages normally requires manual FFI plumbing and external linkers. This Skill documents how to compile a native Jac module into a C-ABI shared library (.so, .dylib, or .dll) that any FFI-capable host can load, with no gcc or ld involved. ## Core Features & Use Cases - Shared library compilation: Run jac nacompile mathlib.jac --shared to emit a host-platform .so, or cross-build Mach-O .dylib and PE .dll artifacts with --target macos / --target windows. - Export surface control: Mark functions, globals, and objects with :pub to define exactly what lands in the export table; methods stay internal and must be wrapped in free functions. - Opaque handle ABI: Pass Jac objects across the boundary as opaque void* handles managed with the exported jac_retain/jac_release refcount helpers. - Use Case: Write a math library in Jac, compile it to libmathlib.so, then call its exported functions from Python via ctypes or link it from a C program with gcc. ## Quick Start Compile my Jac module into a shared library and show me how to call its exported functions from Python ctypes.

Frequently Asked Questions about jac-native-shared

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a shared library from Jac code?

Run jac nacompile mathlib.jac --shared to produce libmathlib.so for the host platform. Use --target macos or --target windows to cross-build a .dylib or .dll; Jac's own linker emits the file without gcc or ld.

How do I call a Jac shared library from Python ctypes?

Load the library with ctypes.CDLL, set restype and argtypes for each exported function, then call it directly. Jac objects arrive as opaque void* handles that you pass back into other exported functions and free with jac_release.

Can I export Jac object methods to C?

No, methods are not exported because they have class-qualified symbols rather than C names. Wrap any method you need in a :pub free function that takes the object as a parameter and calls the method internally.

Why does my shared library build fail with nothing to export?

The build refuses when zero symbols are marked :pub, since a shared library needs an export surface. Mark at least one function, global, or object with :pub; a with entry block is not required for libraries.

Why does an exported global read as 0 when linked from gcc?

Direct extern linking of an exported global reads 0 because copy relocations are unsupported by the emitted .so. Read globals via dlsym or ctypes.in_dll, or expose a :pub accessor function instead.

Can I load-test a cross-built .dylib or .dll on Linux?

No, cross-built Mach-O and PE artifacts are structurally valid but can only be load-tested on their matching operating system. You can build them anywhere, but execution requires macOS or Windows respectively.