Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
加载共享库并获取类型化函数定义
dlopen
Library
function dlopen<Fns extends Record<string, FFIFunction>>( libName: string, defs: Fns, ): Library<Fns>;
import { dlopen, FFIType } from 'arkffi'; const lib = dlopen('libffi_target.so', { add: { args: [FFIType.double, FFIType.double], returns: FFIType.double }, compute: { args: [FFIType.int32, FFIType.double, FFIType.CString], returns: FFIType.double }, }); lib.symbols.add(2.0, 3.0); lib.symbols.compute(0, 4.0, 'square'); lib.close();
libName
string
.so
defs
Record<string, FFIFunction>
interface FFIFunction { args: string[]; // 参数类型编码 returns: string; // 返回类型编码 threadsafe?: boolean; // 用于 JSCallback 定义 }
symbols
import { dlopen, FFIType } from 'arkffi'; const lib = dlopen('lib.so', { myFunc: { args: [FFIType.double, FFIType.double], returns: FFIType.double }, }); lib.symbols.myFunc(2.0, 3.0); // 自动补全
此页面对您有帮助吗?