Closed pmontrasio closed 7 years ago
Unfortunately that's a limitation of escripts. They cannot access anything in priv and therefore they cannot access embedded .so files. In other words, it is not currently possible to build escripts with NIFs in them.
For me, it works if I copy the NIFs into the path that my command line app built with mix escript.build
states in its error message. In my case, I'm using fast_xml which comes with two NIFs, fxml.so and fxml_stream.so.
Without any further action by me, using my app results in
[error] failed to load NIF /Users/...../priv/lib/fxml_stream: Failed to load NIF library: 'dlopen(/Users/......./priv/lib/fxml_stream.so, 2): image not found'
Copying the libs into /priv/lib, the app works as expected. It's a little crude for a production environment, but can probably be automatized with a shell script.
Environment
To provide some context, this is a Raspeberry PI 3 with an external WiFi card. The program I'm working on uses :wierl and :epcap to put that WiFi card in monitor mode and read packets. The
:epcap
module includes a shared library which is built asdeps/procket/priv/procket.so
(btw, the built in WiFi card doesn't support monitor mode, that's why I'm using an external one.)Current behavior
The project directory is
sensor
andmix escript.build
builds the app assensor
. It worked until I added the dependency from:epcap
.Then
Note that the path
/home/me/sensor/sensor/../priv/procket.so
is obviously wrong because of two reasons:1) The second occurrence of
sensor
is actually a file (the app) and not a directory, and the path is wrong even if I manually create apriv
dir under/home/me/sensor
2) The shared library is in
deps/procket/priv/procket.so
There is another shared library in
deps/epcap/priv/epcap_drv.so
but it probably failed first on loadingprocket.so
.Running the application as a mix task or from
iex -S mix
works.Expected behavior
Escript should load the shared library from its path
/home/me/sensor/deps/procket/priv/procket.so