4

I am running CoqIDE to use read the textbook series "Software Foundations", I am currently reading the volume "Logical Foundations". I just started Chapter 2 (Induction), but when I try to run the line

From LF Require Import Basics.

I get an error statement

The file ...\LF\Basics.vo contains library Basics and not library LF.Basics

I tried renaming the directory the file was located in, and recompiled the buffers, but neither of these actions helped. What Shoudl i do in order to solve this problem?

Roquentin
  • 177
  • 2
  • 12

1 Answers1

5

We've been improving the explanation in the soon-to-be-released new version of LF. Here is the relevant bit:

For the [Require Export] to work, Coq needs to be able to
find a compiled version of [Basics.v], called [Basics.vo], in a directory
associated with the prefix [LF].  This file is analogous to the [.class]
files compiled from [.java] source files and the [.o] files compiled from
[.c] files.

First create a file named [_CoqProject] containing the following line
(if you obtained the whole volume "Logical Foundations" as a single
archive, a [_CoqProject] should already exist and you can skip this step):

  [-Q . LF]

This maps the current directory ("[.]", which contains [Basics.v],
[Induction.v], etc.) to the prefix (or "logical directory") "[LF]".
PG and CoqIDE read [_CoqProject] automatically, so they know to where to
look for the file [Basics.vo] corresponding to the library [LF.Basics].

Once [_CoqProject] is thus created, there are various ways to build
[Basics.vo]:

 - In Proof General: The compilation can be made to happen automatically
   when you submit the [Require] line above to PG, by setting the emacs
   variable [coq-compile-before-require] to [t].

 - In CoqIDE: Open [Basics.v]; then, in the "Compile" menu, click
   on "Compile Buffer".

 - From the command line: Generate a [Makefile] using the [coq_makefile]
   utility, that comes installed with Coq (if you obtained the whole
   volume as a single archive, a [Makefile] should already exist
   and you can skip this step):

     [coq_makefile -f _CoqProject *.v -o Makefile]

   Note: You should rerun that command whenever you add or remove Coq files
   to the directory.

   Then you can compile [Basics.v] by running [make] with the corresponding
   [.vo] file as a target:

     [make Basics.vo]

   All files in the directory can be compiled by giving no arguments:

     [make]

   Under the hood, [make] uses the Coq compiler, [coqc].  You can also
   run [coqc] directly:

     [coqc -Q . LF Basics.v]

   But [make] also calculates dependencies between source files to compile
   them in the right order, so [make] should generally be prefered over
   explicit [coqc].

If you have trouble (e.g., if you get complaints about missing
identifiers later in the file), it may be because the "load path"
for Coq is not set up correctly.  The [Print LoadPath.] command
may be helpful in sorting out such issues.

In particular, if you see a message like

    [Compiled library Foo makes inconsistent assumptions over
    library Bar]

check whether you have multiple installations of Coq on your machine.
It may be that commands (like [coqc]) that you execute in a terminal
window are getting a different version of Coq than commands executed by
Proof General or CoqIDE.

- Another common reason is that the library [Bar] was modified and
  recompiled without also recompiling [Foo] which depends on it.  Recompile
  [Foo], or everything if too many files are affected.  (Using the third
  solution above: [make clean; make].)

One more tip for CoqIDE users: If you see messages like [Error:
Unable to locate library Basics], a likely reason is
inconsistencies between compiling things _within CoqIDE_ vs _using
[coqc] from the command line_.  This typically happens when there
are two incompatible versions of [coqc] installed on your
system (one associated with CoqIDE, and one associated with [coqc]
from the terminal).  The workaround for this situation is
compiling using CoqIDE only (i.e. choosing "make" from the menu),
and avoiding using [coqc] directly at all. *)
Benjamin Pierce
  • 497
  • 2
  • 10
  • Thank you very much for your response. I followed through your comment. On my system, everything is following the specifications of your comment. I only have one installation of Coq, I downloaded Coq as an archive so _Coqproject exists and has the correct line stored in it, Basics.vo exists, I compiled Coq from CoqIDE only. I think _Coqproject isn't being run correctly because I am getting the error message that Basics and not LF.Basics exists. Do you have any idea as to what I can do to fix that? – Roquentin Dec 18 '18 at 00:48
  • I think I forgot to run "make" on basics either before or after compiling buffers, but now it works. Thank you very much for your help. – Roquentin Dec 18 '18 at 00:55
  • Thanks. I think it's better to put this hint earlier in the book. I met this problem when I tried to test my exercises in Chapter Basics. – namasikanam Oct 20 '19 at 13:39