我正在研究一个问题的解决方案,该问题需要更改模块 gb_trees
的其中一个功能。
我在编译 gb_trees
的编辑版本时遇到错误:
1> c(gb_trees).
cannot write to .bea#
...
2>
我可以通过什么方式来修改和编译一个已经存在的模块?
最佳答案
可能您的文件正在被另一个进程使用。关闭您正在使用的所有应用程序或重新启动操作系统,然后尝试重新编译。
您正在尝试手动加载模块,它是 Erlang/OTP 的一部分。
来自文档:
The Erlang runtime system is protecting you.
The easiest solution is to rename your module, e.g. to mysets.erl. It is also possible to 'un-stick' the directory containing the library module.
参见 code:unstick/1
.
还有:
To prevent accidentally reloading modules affecting the Erlang runtime system itself, the
kernel
,stdlib
andcompiler
directories are considered sticky. This means that the system issues a warning and rejects the request if a user tries to reload a module residing in any of them. The feature can be disabled by using the command line flag-nostick
.
参见 erl(1)
.
例如:
$ erl -nostick
Eshell V5.7.3 (abort with ^G)
1> c(gb_trees).
{ok,gb_trees}
2> gb_trees:module_info().
[{exports,[{foo,2},{module_info,0},{module_info,1}]},
{imports,[]},
{attributes,[{vsn,[338095567601101424197378397768992511838]}]},
{compile,[{options,[]},
{version,"4.6.3"},
{time,{2011,2,3,11,39,53}},
{source,"/tmp/gb_trees.erl"}]}]
3>
您会看到我们可以编译模块并将其加载到 VM 中。
但是,您可以将模块 gb_trees
重命名为 gb_trees_mine
并使用它导出的函数:
1> gb_trees_mine:foo(13,42).
bar
2>
关于二郎/OTP : Changes to the already existing modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4885443/