编译
-
单个文件编译
在Erlang Shell运行c(ModuleName).
进行编译。c(ModuleName, Options)
也可以通过Options
添加编译选项。 -
通过定制
Emakefile
来管理编译%% Emakefile { %% 源码路径 [ 'src/**/*' ], %% 编译选项 [ debug_info,%% 添加debug_info编译后,可反编译回源码。 nowarn_export_all,%% 不警告全导出。 {parse_transform, ModuleName},%% 在代码错误检查之前调用ModuleName:parse_transform/2先把代码解析一遍。 {i, "include"},%% 头文件目录 {outdir, "ebin"}%% 输出目录,即beam文件目录 ] }.
创建脚本如下,运行即可编译所有文件。
## make.bat erl -noshell -s make all -s init stop
make
-
通过调用
make:all().
或者make:all(Options).
来编译模块。其中,
Options
为noexec | load | netload | {emake, Emake} | <compiler option>
。noexec
选项指只打印将会编译的模块名而不会进行编译。load
和netload
选项指编译后对代码进行加载,netload
会在所有已知节点加载。{emake,Emake}
选项指定Emake配置文件,指定时则使用Emake
文件的配置,否则在当前目录下查找文件名为Emakefile
的文件,读取其中的配置。默认情况下Options
为[]
。 -
通过调用
make:files(ModFiles).
或者make:files(ModFiles, Options).
同样可以编译模块。
上述方法最终都会通过调用compile:file(File, Options).
对文件进行编译。
Emakefile
格式如下:
Modules.
{Modules,Options}.
Modules
指明编译的模块。
Options
为编译选项。编译选项见compile
模块的说明。
compile
-
可通过
compile:env_compiler_options().
获取设置的编译选项。 -
可通过
compile:file(File).
或者compile:file(File, Options).
对模块进行编译。常见编译选项如下:
debug_info
选项指定在编译后的beam
文件的debug_info
中包含抽象代码,使其可用于Debugger等工具。{outdir,Dir}
选项指定编译后的beam
的目录。{i,Dir}
选项指定头文件所在目录。{d,Macro}
、{d,Macro,Value}
选项定义了宏Marco
的值,默认为true
。{parse_transform,Module}
选项在代码错误检查之前调用ModuleName:parse_transform/2
先把代码解析一遍。nowarn_export_all
选项关闭了export_all
的警告输出。'P'
在文件<File>.P
中生成经过预处理和解析转换的代码。'E'
在文件<File>.E
中生成执行了所有源代码转化之后的代码。'S'
在文件<File>.S
中生成汇编程序代码。