docs

您正在閱讀 v0.1.2 的文件。Nabi 0.1.2 已停止支援。 最新版本:v0.1.3 →

本頁尚未翻譯,以下為英文原文。

#E0126: link failed

The program type-checked, but the link failed: the linker reported an error, or could not find a native library. nabic check stops before linking, so a link failure shows up only when building (nabi build, nabi run, nabic build). The usual cause is a function declared in an extern block whose library is not linked: libc and libm are linked by default, anything else needs #[link] (6.2.3). Check the -L directories and #[link] names.

This program calls a zlib function without linking zlib:

nabi
extern "C" {
    fn compressBound(len: u64) -> u64;
}

println(f"{unsafe { compressBound(1000) }}");

On macOS, nabic build prints (shortened; the symbol has no leading _ on other platforms):

text
   Compiling main (.)
error[E0126]: the link failed:
undefined symbol: _compressBound
>>> referenced by .../module0.o
...

compressBound is in zlib. Link it:

nabi
#[link("z")]
extern "C" {
    fn compressBound(len: u64) -> u64;
}

println(f"{unsafe { compressBound(1000) }}");
1013

Related: E0127 external tool failed, E0084 invalid foreign-function use

Found a mistake? Edit this page on GitHub. Last updated