调试信息的正确选项是debug_info
:
1> compile:file(hello, [debug_info, export_all]).
{ok,hello}
另一方面,我不明白的是为什么编译总是成功,而且在传递不存在的选项时也是如此?
例如
2> compile:file(hello, [debug, export_all]).
{ok,hello}
或
3> compile:file(hello, [foobar, export_all]).
{ok,hello}
为什么这两个例子不报错?
最佳答案
在 Erlang 中忽略无效选项是很常见的。选项以默认值获取。像这样的事情:
1> Opts = [{opt1, 1}, {other, 2}].
[{opt1,1},{other,2}]
2> %% Inside function
2> Opt1 = proplists:get_value(one, Opts, 1),
2> Opt2 = proplists:get_value(two, Opts, 2).
2
3> Opt1.
1
4> Opt2.
2
5>
关于compilation - 为什么Erlang编译:file does not report error for unknown options?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43954074/