我创建了我的第一个Erlang项目。这是一个简单的秘密密码游戏。我正试图不惜一切代价避免OTP,因为它似乎真的令人困惑,而我的导师认为没有必要使用它。
我有三个文件夹: ebin src测试
我使用makefile编译所有代码并运行测试。
今晚之前生活是美好的..。
来嘲笑我的输入(和输出?)对于这个游戏,建议我使用Meck,但是我很难将它集成到我的项目中。
我试过手动安装。我克隆了梅克。我可以将"cd“放入Meck目录中的eBin文件夹并编译,运行所有系统测试,并执行一个基本命令"meck:new(dog)”。太棒了!
现在我需要让Meck使用我的项目.我在Github自述中读到了这一行:“如果您想安装自己构建的Meck版本,请将ebin目录添加到您的Erlang代码路径中,或者将meck文件夹移动到您的发布文件夹中,并确保该文件夹位于您的ERL_LIBS环境变量中。”
但是我不知道如何将ebin目录添加到我的Erland代码路径中,我没有发布文件夹(我认为这是钢筋的事情吗?)我不知道如何添加一个ERL_LIBS环境变量。所以我卡住了。
下面是我尝试过的:要将ebin目录添加到我的代码路径中,我在makefile中这样做了(我现在的桌面上有meck目录):
erlc -pa ~/Desktop/meck/ebin/我将ERL_LIBS添加到我的.bash_profile中,如下所示:
export ERL_LIBS='~/Desktop/meck/ebin/'我还尝试安装Agner并在安装时获得错误:
ERROR: compile failed while processing /private/tmp/agner.0r04Vm: {'EXIT',
{undef,
[{rebar,get_jobs,
[{config,"/private/tmp/agner.0r04Vm",
[{require_otp_vsn,"R14|R15"},
{lib_dirs,["deps"]},
{escript_incl_apps,
[getopt,gproc,rebar,plists,gen_fsm2,jsx]},
{erl_opts,[{i,"deps"}]},
{plugins,[agner_rebar_plugin]},
local]}],
[]},
{rebar_base_compiler,run,4,
[{file,"src/rebar_base_compiler.erl"},{line,49}]},
{rebar_erlc_compiler,doterl_compile,3,
[{file,"src/rebar_erlc_compiler.erl"},{line,157}]},
{rebar_core,run_modules,4,[{file,"src/rebar_core.erl"},{line,420}]},
{rebar_core,execute,4,[{file,"src/rebar_core.erl"},{line,354}]},
{rebar_core,process_dir0,6,[{file,"src/rebar_core.erl"},{line,217}]},
{rebar_core,process_dir,4,[{file,"src/rebar_core.erl"},{line,128}]},
{rebar_core,process_commands,2,
[{file,"src/rebar_core.erl"},{line,83}]}]}}
make: *** [compile] Error 1有人能帮忙吗?我觉得我有好几种选择可以尝试,但没有一种可行。
更新:
下面是我的make文件在阅读@d11wtq的解决方案后的样子:
.SUFFIXES: .erl .beam .yrl
.erl.beam:
erlc -W $<
.yrl.erl:
erlc -W $<
ERL = erl -boot start_clean
MODS = console_io feedback mastermind secret_code meck
all: compile path run_test
compile:
erlc -o ebin/ src/*.erl
erlc -o ebin/ test/*.erl
path:
erlc -pa ebin/
-env ERL_LIBS deps/
run_test:
erl -noshell -pa ebin \
-eval 'eunit:test("ebin").' \
-eval 'mastermind:start_game().' \
-s init stop
clean:
rm -rf ebin/*.beam
rm -rf erl_crash.dump最后更新:
根据这些技巧,这是我的最后一个makefile,现在起作用了。
all: compile run_test run_game
compile:
erlc -o ebin/ src/*.erl
erlc -o ebin/ test/*.erl
run_test:
erl -pa ebin \
-env ERL_LIBS deps/ \
-eval 'eunit:test("ebin").' \
-s init stop
run_game:
erl -pa ebin \
-env ERL_LIBS deps/ \
-eval "mastermind:start_game()." \
-s init stop
clean:
rm -rf ebin/*.beam
rm -rf erl_crash.dump发布于 2013-05-12 08:45:47
只需将meck (及其所有子目录)放在项目的子目录中即可;例如,deps/。
所以现在你会有:
src/
ebin/
deps/
meck/
src/
ebin/因为Erlang中的lib与应用程序打包的方式相同,所以有一个环境变量ERL_LIBS将告诉VM在哪里找到应用程序使用的库。麦可是其中之一,它在路径"deps/“。
erl -pa ebin/ -env ERL_LIBS deps/现在,meck对Erlang应该是可见的。
发布于 2013-05-12 16:31:09
引用梅克自述
Meck最好通过钢筋来使用。在项目根目录中添加
rebar.config的以下依赖项: {deps,{meck,".*",{git,"https://github.com/eproxus/meck.git"}} }。
然后运行rebar get-deps和rebar compile。
https://stackoverflow.com/questions/16503603
复制相似问题