0

I have used reabr3 to create an application to practice the RabbitMQ but the rebar3 can not load the additional file I created in the src folder to erlang shell.

I used rebar3 new app rabbit. I had rabbit_app.erl rabbit_sup.erl and rabbit.app.src and a new defined file named hello_world.erl in the src/ directory. I ran the rebar3 compile to compile and get dependencies.

Then ran rebar3 shell to able to test the function in hello_world.erl. The hello_world.beam can not be loaded so I have to use the c(hello_world) manually in erlang shell. It is a bit inconvenient.

Any helps would highly be appreciated. Here is the console output for rebar3 compile and rebar3 shell.

$ rebar3 compile
===> Verifying dependencies...
===> Fetching amqp_client v3.8.14
===> Fetching rabbit_common v3.8.7
===> Fetching credentials_obfuscation v2.2.0
===> Fetching jsx v2.11.0
===> Fetching lager v3.8.0
===> Fetching ranch v1.7.1
===> Fetching recon v2.5.1
===> Fetching goldrush v0.1.9
===> Analyzing applications...
===> Compiling credentials_obfuscation
===> Compiling goldrush
===> Compiling jsx
===> Compiling lager
===> Compiling ranch
===> Compiling recon
===> Compiling rabbit_common
===> Compiling amqp_client
===> Analyzing applications...
===> Compiling rabbit

$ rebar3 shell
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling rabbit
Erlang/OTP 22 [erts-10.7.2.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [hipe]

Eshell V10.7.2.1  (abort with ^G)
1> ===> Booted xmerl
===> Booted compiler
===> Booted sasl
===> Booted syntax_tools
===> Booted tools
===> Booted goldrush
===> Booted lager
===> Booted jsx
===> Booted ranch
===> Booted recon
===> Booted credentials_obfuscation
===> Booted rabbit_common
===> Booted amqp_client
===> Booted rabbit
 

[UPDATE] I found that the new added files were load but the auto-complete for these files did not work. I had to use the whole command for the first time.

tandathuynh148
  • 190
  • 5
  • 15

1 Answers1

0

rebar3 organizes the .beam files in directories outside the src directory. When you issue the command c(hello_world), the .beam file is placed in the current directory. Apparently, you are issuing your rebar3 commands while the current directory is the src/ directory, which is not the way things are done with rebar3. You need to be in the rabbit/ directory, i.e. the top level directory of your app, when you issue rebar3 commands like rebar3 compile and rebar3 shell.

7stud
  • 46,922
  • 14
  • 101
  • 127
  • Yes, I was in the `rabbit/` directory when I issued the `rebar3 compile and rebar3 shell`. I could see the `_build/default/lib/rabbit/ebin/hello_world.beam`. But I am not able to call `hello_world` module in the shell. – tandathuynh148 Jun 08 '21 at 13:07
  • @tandathuynh148, Show your command line commands, shell commands, and output. By that, I don't mean that you should describe what you did, instead post the actual commands and output, starting with creating the app. – 7stud Jun 08 '21 at 13:14
  • Thank you so much. You can find the output of the commands here: https://imgur.com/Y8rZOMZ and https://imgur.com/aSFrFN2 – tandathuynh148 Jun 08 '21 at 21:53
  • @tandathuynh148, could you also check if `hello_world` is listed in `modules` list of `_build/default/lib/rabbit/ebin/rabbit.app` file? Also what version of `rebar3` are you using? – Venkatakumar Srinivasan Jun 09 '21 at 17:55
  • @tandathuynh148, Sorry, that isn't the way things are done on stackoverflow. Copy and paste your commands and output and post them at the bottom of your question. Linking to images is terrible form--and don't post images either. – 7stud Jun 09 '21 at 22:44
  • Hi @7stud, I have updated the console output. Hi @VenkatakumarSrinivasan, the `hello_world` was listed in the modules of `rabbit.app` – tandathuynh148 Jun 14 '21 at 15:22
  • @tandathuynh148, The output you posted does not match what you described above the output. Try this: create a new app called `rabbit2`, then add hello_world.erl to the `src/` directory. Then change directories back to the top level rabbit2 directory, then issue the command `rebar3 compile`, then `rebar3 shell`. Does calling a function defined in hello_world.erl work now? – 7stud Jun 14 '21 at 17:34
  • Hi @7stud, I just found that it worked. But the auto-complete when I type the command prefix did not work, I have to type the whole command – tandathuynh148 Jun 15 '21 at 12:17