Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading specific module from external project

Tags:

erlang

I have a project composed of several apps. The apps use some of the same records and functions to communicate, so I would like to make a module "shared" between them.
I tried using the code:add_path and code:load_file functions but the app still crashes with an undef error when trying to access those shared functions.
The apps are started using different escript methods (rebar3 shell and make run with erlang.mk).

  1. How do I add an external module in the makefile method (I know in rebar3 there's an {extra_src_dirs, []} option)?
  2. What is the best way to load and add the shared module in code in runtime?

EDIT:
I also tried using code:load_abs and adding -pa <file_path> to vm.args

like image 490
halfway258 Avatar asked May 09 '26 22:05

halfway258


1 Answers

I succeeded by simply using code:load_abs("<file_path>.beam"), and having a symlink to the original .erl file with the other source code. According to the documentation the extension needs to be omitted, which threw me off.

EDIT: use a hardlink instead, for some reason my changes stop taking affect at some point between the files..

like image 117
halfway258 Avatar answered May 12 '26 12:05

halfway258