gpt4 book ai didi

visual-studio-2013 - 错误构建 F# :"Files in libraries or multiple-file applications must begin with a namespace or module declaration"

转载 作者:行者123 更新时间:2023-12-02 09:20:55 25 4
gpt4 key购买 nike

我有一个 Program.fs 使用的名为 BasicFunctions.fs 的文件。
BasicFunctions.fs 在项目中肯定在 Program.fs 之上,所以顺序是正确的。但我不断收到此错误:

错误 1 ​​库或多文件应用程序中的文件必须以命名空间或模块声明开头,例如“命名空间 SomeNamespace.SubNamespace”或“模块 SomeNamespace.SomeModule”。只有应用程序的最后一个源文件可以省略这样的声明。

我正在使用带有 F# 3.1 的 VS 2013。
这是示例代码,没什么特别的:

基本功能.fs

module BasicFunctions

let runAll =
let result = 4
result

程序.fs
[<EntryPoint>]
let main argv =
printfn "%A" argv
BasicFunctions.runAll
0 // return an integer exit code

这是解决方案的屏幕截图:

VS Screenshot

最佳答案

我发现了问题。当您复制和粘贴 .fs 文件而不是从头开始创建新文件时,似乎存在问题。使用谷歌找到这个链接:
https://github.com/Microsoft/visualfsharp/issues/104

为了解决这个问题,我刚刚删除了 BasicFunctions.fs 和 BasicFunctions2.fs 这两个文件,并使用 创建了它们。 “新项目..” VS 中的菜单项,同时确保它们位于主文件 Program.fs 之前。

如果您不想重新创建文件的麻烦,最好实际修改 .fsproj 文件以确保 Program.fs 是最后一个文件。归功于 rmunn 在评论部分。

现在已经搭建成功了,感谢大家的帮助。

关于visual-studio-2013 - 错误构建 F# :"Files in libraries or multiple-file applications must begin with a namespace or module declaration",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42663418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com