@export

@export

@export(declaration, comptime options: std.builtin.ExportOptions) void

Creates a symbol in the output object file.

declaration must be one of two things:

  • An identifier (x) identifying a function or a variable.
  • Field access (x.y) looking up a function or a variable.

This builtin can be called from a comptime block to conditionally export symbols. When declaration is a function with the C calling convention and options.linkage is Strong, this is equivalent to the export keyword used on a function:

test.zig

comptime {
    @export(internalName, .{ .name = "foo", .linkage = .Strong });
}

fn internalName() callconv(.C) void {}

Shell

$ zig build-obj test.zig

This is equivalent to:

test.zig

export fn foo() void {}

Shell

$ zig build-obj test.zig

Note that even when using export, @"foo" syntax can be used to choose any string for the symbol name:

test.zig

export fn @"A function name that is a complete sentence."() void {}

Shell

$ zig build-obj test.zig

When looking at the resulting object, you can see the symbol is used verbatim:

00000000000001f0 T A function name that is a complete sentence.

See also:

  • Exporting a C Library