即使所有正确的导入和正确配置的混合文件,我也无法生成可执行文件,并且出现以下错误:
warning: DesafioCumbuca.main/1 is undefined or private. Did you mean:
* main/0
└─ /home/runner/work/elixir/elixir/lib/mix/lib/mix/tasks/escript.build.ex:396: :desafio_cumbuca_escript.main/1
desafio_cumbuca.ex 文件:
`
defmodule DesafioCumbuca do
alias InterfaceUsuario
alias ObterNomes
alias EnumerarNomes
def main() do
InterfaceUsuario.mostrar_boas_vindas()
nomes = ObterNomes.obter_nomes([])
nomes_ordenados = EnumerarNomes.enumerar(nomes)
InterfaceUsuario.mostrar_resultado(nomes_ordenados)
end
end`
混合文件:
defmodule DesafioCumbuca.MixProject do
use Mix.Project
def project do
[
app: :desafio_cumbuca,
version: "0.1.0",
elixir: "~> 1.17",
start_permanent: Mix.env() == :prod,
deps: deps(),
escript: escript()
]
end
def escript do
[main_module: DesafioCumbuca]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
为了生成可执行文件,我打开项目页面并输入“mixcompile”,然后输入“mixescript.build”
正如错误消息所指出的,您的
main
函数的数量是 0
(不接受任何参数),但 escript 期望它是 1
,正如您在这个 example 中看到的那样。
更换以下内容
def main() do
由
def main(_args) do
应该修复它。