I have a Coq project with its libraries organized in subdirectories, for example:
…/MyProj/Auxiliary/Aux.v …/MyProj/Main/Main.v (imports Auxiliary/Aux.v)
When I compile the files, I expect to do this from the MyProj working directory (via the make file). But I also want to work with files using Proof General / Coqtop, in which case the default working directory is the directory where the file is located.
But this means that LoadPath is different between the two contexts, and therefore the logical path required to import the library is different. How to set up coqc, LoadPath and import declarations to work in both contexts?
Every approach I tried is something wrong. For example, if I compile Aux.v by calling
coqc -R "." "MyProj" Auxiliary/Aux.v
and import it into Main.v as
Require Import MyProj.Auxiliary.Aux.
then this works when I compile Main.v with
coqc -R "." "MyProj" Main/Main.v
but not executed in Coqtop, with Error: Cannot find library MyProj.Auxiliary.Aux in loadpath . On the other hand, if before Require Import I add
Add LoadPath ".." as MyProj.
then it works in Coqtop, but fails with coqc -R "." "MyProj" Main/Main.v coqc -R "." "MyProj" Main/Main.v , moreover
Error: The file […]/MyProj/Auxiliary/Aux.vo contains library
MyProj.Auxiliary.Aux and not the MyProj.MyProj.Auxiliary.Aux library
We are looking for a solution that is reliable for a library that is shared by the co-authors (and, I hope, ultimately with users), therefore, in particular, it cannot use absolute file paths. The best I have found now is to add local emacs variables to set LoadPath when Proof General calls Coqtop:
((coq-mode . ((coq-prog-args . ("-R" ".." "MyProj" "-emacs")))))
but this one (a) seems a bit hacky, and (b) works only for proof, not Coqide or plain Coqtop. Is there a better solution?