Skip to main content

Extern (FFI)

The extern keyword declares functions defined in external C/C++ libraries.


Syntax

extern method Add(a as float, b as float) as float;

This declares Add as an external function with the given signature. The implementation is provided by a linked native library or provider, not by Morph source in the same compilation unit.


Usage

extern method NativeCompute(x as float) as float;

Init method() {
result is NativeCompute(3.14);
Print(result);
}

Linking and native providers

There is no generic [build].extra_link_dirs / extra_link_libs table in the ProjectConfig loader today. Link flags and library search paths come from:

  • your native provider / CMake integration under [native.<Name>], and/or
  • platform packaging and product build flows.

Configure the native artifact (.lib / .dll / .so) through the same manifest pipeline described in Native providers.


Targets

extern presupposes a native link step. Container-only or strictly sandboxed targets may not support arbitrary FFI; treat extern like unsafe: native-first, and verify your deployment story.


Restrictions

  • No method body — the symbol must exist in native code.
  • Typing and calling convention must match what the linker and ABI expect.

Next steps