OxL Справочник OxL
РусскийEnglish

error ffi-import

error Стандарт: [§16.1]

Не удалось импортировать заголовок C.

What it means#

import c "header.h" { names } reads the header with libclang at compile time (§16.1). The error is reported when the header cannot be found or parsed, or when a listed name does not exist in it or has a type that cannot be mapped to OxL (variadic functions, unions, bit-fields, packed structs, long double, structs passed by value). The same code reports types without a C representation in hand-written extern c fn / export c fn signatures (str, String, List<T>, char, structs by value) and in @c_layout data fields.

Example#

oxl✓ проверяется в CI
import c "zlibb.h" { deflate }      // <- ffi-import (no such header)
error
ffi-import
oxl
extern c fn puts(s: str) -> i32      // <- ffi-import: `str` has no C representation

How to fix#

oxl✓ проверяется в CI
import c "zlib.h" { deflate, inflate, z_stream }

For strings use std.ffi: str.toCString() gives an owned NUL-terminated buffer (.asPtr() is a *u8), CStr.fromPtr(p) reads one back; pass structs as *var S. Check the header name and the include path of the native dependency declared in [deps] (for example zlib = { c = "system", header = "zlib.h" }).

See also#

OxL 1.0.0-beta · Версия документации 1.0.0-beta© OxwaldLink · сгенерировано из Стандарта, исходников std и руководства