【问题标题】:how to include .hrl files across multiple modules rebar3如何在多个模块中包含 .hrl 文件 rebar3
【发布时间】:2018-04-23 09:38:15
【问题描述】:

我有几个模块的目录。对于每个模块,我将include(包含*.hrl 文件)和src(包含*.erl 文件)文件夹分开。如何在不复制模块的情况下将 *.hrl 文件从一个模块共享到另一个模块?

使用钢筋,我添加了{erl_opts, [{i, "folderContainsIncludeFile"}]},它起作用了。

但是使用rebar3,编译失败,说找不到包含文件“include/xx.hrl”

【问题讨论】:

  • 你试过用-include_lib代替-include吗?
  • 是的,我试过了,但还是不行……

标签: erlang rebar rebar3 relx


【解决方案1】:

我认为你没有一个总括项目,你只是在同一级别有多个目录,每个目录都有自己的项目,由 rebar3 管理。 比如:

root_folder
 |- project1
 |  |- src
 |  |- include
 |  |  `- one.hrl
 |  `- rebar.config
 |- project2
 |  |- src
 |  |  `- two.erl
 |  |- include
 |  `- rebar.config
 …

并且您想将one.hrl 包含在two.erl 中。

如果是这种情况,您应该考虑以下替代方案之一:

A.转向伞形项目结构,例如……

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 构建应用程序的路径。像……

ERL_LIBS=$ERL_LIBS:/path/to/root_folder/project1/_build/lib:/path/to/root_folder/project2/_build/lib:…

希望这会有所帮助:)

【讨论】:

    猜你喜欢
    • 2018-01-10
    • 2016-12-29
    • 2023-03-29
    • 1970-01-01
    • 2019-08-16
    • 2016-02-05
    • 2021-04-16
    • 1970-01-01
    • 2017-09-26
    相关资源
    最近更新 更多