我有几个模块的目录。对于每个模块,我将include
(包含*.hrl
文件)和src
(包含*.erl
文件)文件夹分开。如何*.hrl
在不复制模块的情况下将文件从模块共享到另一个模块?
使用钢筋,我添加了{erl_opts, [{i, "folderContainsIncludeFile"}]}
它并且它起作用了。
但是使用rebar3,编译失败,说找不到包含文件“include/xx.hrl”
我认为你没有一个伞形项目,你只是在同一级别有多个目录,每个目录都有自己的项目,由 rebar3 管理。就像是:
root_folder
|- project1
| |- src
| |- include
| | `- one.hrl
| `- rebar.config
|- project2
| |- src
| | `- two.erl
| |- include
| `- rebar.config
…
并且您想包含one.hrl
到two.erl
.
如果是这种情况,您应该考虑以下替代方案之一:
A. 转向伞形项目结构,例如……</p>
root_folder
|- rebar.config <<<<<<<< notice this file is here now
`- apps
|- project1
| |- src
| `- include
| `- one.hrl
|- project2
| |- src
| | `- two.erl
| `- include
…
B. 为每个项目使用单独的存储库,并将它们配置为相互依赖。该结构就像您当前拥有的结构一样,但现在您必须添加deps
到 rebar.config 中。例如,在我们的示例中,您应该将以下行添加到 project2 的 rebar.config:
{deps, [project1]}.
(如果您设法在 hex.pm 中发布 project1)
C. 正确设置$ERL_LIBS
,使其包含使用 rebar3 构建应用程序的路径。像……</p>
ERL_LIBS=$ERL_LIBS:/path/to/root_folder/project1/_build/lib:/path/to/root_folder/project2/_build/lib:…
希望这可以帮助 :)