erlang 中 include 和include_lib

 
 

code path:
the code path consists of the current working directory and all Erlang object
code directories under the library directory $OTPROOT/lib, where $OTPROOT
is the installation directory of Erlang/OTP, code:root_dir().

code:lib_dir/1:
这个函数主要用于查找库目录的路径,例如一个名为 Name 且放在 $OTPROOT/lib 目录下的应用的根目录,
或是引自于 ERL_LIBS 环境变量下的一个目录。
If there is a regular directory called Name or Name-Vsn in the code path with
an ebin subdirectory, the path to this directory is returned (not the ebin directory).

所以:原来写的
-include("../client_dev/include/client_dev.hrl").是错的,应该是
-include("./deps/client_dev/include/client_dev.hrl").还是错的:
通过code:lib_dir/1 的解释:
实际上:
code:lib_dir(client_dev).结果是:
"/home/dev/Work/cheetah/wxclient/deps/client_dev"

就要该成:
-include_lib("client_dev/include/client_dev.hrl").

-include("wxclient.hrl"). 这个 wxclient.hrl 是在 include/ 下面的
是在编译的时候包含进去, 这个配置在
rebar.config 的 erl_opt 的 -i 参数, 相当于erlc

---可以通过-include和-include_lib来包含文件,两者的区别是include-lib不能通过绝对路径查找文件,
而是在你当前Erlang的lib目录进行查找。摘自 http://www.cnblogs.com/samis/archive/2011/05/03/2034957.html

down vote
I think you can use:

-include_lib("snmp/include/snmp_types.hrl").
include_lib is similar to include, but should not point out an absolute file. Instead, the first path component (possibly after variable substitution) is assumed to be the name of an application.

Example:
-include_lib("kernel/include/file.hrl").
The code server uses code:lib_dir(kernel) to find the directory of the current (latest) version of Kernel, and then the subdirectory
include is searched for the file file.hrl.
<./pre>

转载于:https://www.cnblogs.com/ShankYan/p/4365162.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值