Error: Don't know how to build <filename>

Hi folks,

When i try compile my with the command:

$ dune build scanner.exe

i receive the following message in my terminal:

Error: Don’t know how to build scanner.exe
Done: 0/0 (jobs: 0)

I’m using Ubuntu 20.04.1 LTS
Dune 2.7.0
opam 2.0.7

Hi @tiagosardi,

Try dune build ./scanner.exe (need a leading ./ for executables in the current directory). I believe there is a hint for this… not sure why you’re not getting it with your setup.

If that doesn’t work, can you post the dune file you’re using?

1 Like

Dune builds according to the project layout. So if you have:


And if you are in the project root directory, then you can run:

dune build bin/scanner.exe

Hi CraigFe,

i pushed the project to:

For compile tests, i had build a hello world in:

The hello world worked to the command:

$ dune build ./hello.exe

But the doesn’t works with:

$ dune build ./scanner.exe

Hi @yawaramin,

i’ am building in

$ dune build /src/scanner-adhoc/scanner.exe

Executables must be specified inside (executable ...) stanzas in a dune file in the same directory as the executable.

In src/scanner-adhoc/dune, you define the executable scanner-test, but no executable for the scanner module, hence the error message. You could add a new stanza for scanner, but then Dune will require you to specify which modules belong to which executables (which is a problem for your case, since scanner-test requires code supplied by scanner).

If you want to define some common code that’s used by two executables, you should use a single library stanza and two executable stanzas that depend on it:

 (name scanner)
 (modules ...))

 (name scanner-bin)
 (libraries scanner)
 (modules scanner-bin))

 (name scanner-test)
 (libraries scanner)
 (modules scanner-test))

This will have the advantage of keeping your library code (scanner) distinct from the run-time side-effects that it currently defines. (If you didn’t do this, any code that depends on Scanner (in this case, scanner-test) would end up inheriting its run-time side-effects too.) Even better, you could split the scanner-adhoc folder into lib/, bin/ and test/ (each with their own dune file), and then you wouldn’t need to tell Dune which modules correspond to which build artefacts.

1 Like

Thanks @CraigFe. I understood how the build works!! And i separated the files in distint folders. Now i’m ready to resolved my asks about the implementation. Thanks again!!

1 Like

Also is not a legal name for OCaml files. You’ll need to change it to And the module name will be Scanner_test.

1 Like