erlang的makefile编译问题

来源:互联网 发布:启明软件股份有限公司 编辑:程序博客网 时间:2024/05/21 23:33

最近一直在看erlang程序设计,但是一直卡在第十五章的makefile那里(make和gcc菜鸟一枚)。弄了几天终于把问题解决了。

先感谢一下这篇博客“对在erlang中的makefile一些解释” 。下面是解释及问题解决:

由于作者在《Erlang程序设计》书中提供的makefile是在Mac OS X系统中测试的,并没有linux版本,所以就想着自己捣鼓一个makefile出来。但由于之前都没有使用makefile编译过程序,所以就花了一些时间去学习make。先上我修改后的makefile文件:

.SUFFIXES: .erl .beam.erl.beam:erlc -W $<MODS = example1all: ${MODS:%=%.beam} example1 example1_drv.soexample1: example1.c erl_comm.c example1_driver.c        gcc -o example1 example1.c erl_comm.c example1_driver.c example1_drv.so:  example1.c        gcc -I /opt/erlang/lib/erlang/usr/include\-o example1_drv.so example1.c example1_driver.c erl_comm.cclean:        rm example1 example1_drv.so *.beam


其中,.SUFFIXES声明要用到的或者将生成的文件的类型;.erl.beam是指所有.beam文件都是依赖于.erl文件的,下一行的命令就是把所有.erl文件编译成.beam文件;MODS是定义的变量;clean是删除编译生成的各种文件。

与原来的makefile文件相比,主要修改了两处地方:把MODS变量的example1_lib, unit_test删掉,修改example1_drv.so中的gcc命令。而example1_drv.so中的/opt/erlang/lib/erlang/usr/include是我电脑上安装erlang的文件位置。改完之后,使用命令make all就编译成功了。

虽然花了比较多的时间,但学习了make和makefile,算是有所收获。继续加油!

0 0