Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error building F#:"Files in libraries or multiple-file applications must begin with a namespace or module declaration"

I have a file called BasicFunctions.fs which is used by Program.fs. BasicFunctions.fs is definitely above Program.fs in the project so the order is correct. But I keep on getting this error:

Error 1 Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'. Only the last source file of an application may omit such a declaration.

I am using VS 2013, with F# 3.1. Here is the example code, nothing special:

BasicFunctions.fs

module BasicFunctions

let runAll = 
    let result = 4
    result

Program.fs

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

Here is the screenshot of the solution:

VS Screenshot

like image 351
Daniel PP Cabral Avatar asked Oct 15 '25 16:10

Daniel PP Cabral


1 Answers

I found the problem. There seems to be an issue when you copy and paste .fs files instead of creating a new file from scratch. Found this link using google: https://github.com/Microsoft/visualfsharp/issues/104

To resolve the issue I just deleted the two files BasicFunctions.fs and BasicFunctions2.fs and created them using the "New Item.." menu item in VS, also ensuring that they are before the main file Program.fs.

If you don't want the hassle of re-creating files, it would be better to actually modify the .fsproj file to ensure that Program.fs is the last file. Credit goes to rmunn in the comments section.

It's building successfully now, thanks for everyone's help.

like image 111
Daniel PP Cabral Avatar answered Oct 18 '25 04:10

Daniel PP Cabral



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!