E4067#
main 包中缺少 main
函数
In MoonBit, packages are divided into two types: main packages and non-main
packages. Non-main packages are often used as libraries to provide functionality
to other packages. Main packages, on the other hand, are the entry points of the
program. Therefore, main package should contains a main
function serving as
the entry point of the program.
错误示例#
Suppose in package main
:
main/moon.pkg.json
:
{ // Error: Missing main function in the main package.
"is-main": true
}
main/main.mbt
:
type A Int
pub fn A::to_int(self : A) -> Int {
self._
}
建议#
You can add a main
function to the main package:
main/main.mbt
:
// ...
fn main {
let a : A = 42
println(a.to_int())
}
Alternatively, you can set the package to be a non-main package by setting
"is-main"
to false
in the package configuration file.
main/moon.pkg.json
:
{
"is-main": false
}