LZ4 client for Elixir

I want to encode and decode strings using lz4 library https://lz4.github.io/lz4/

Is there any bindings available for elixir?

Let me Hex that for you.

4 Likes

I am getting unable to compile :lz4 error.

Can you please help?

No one can help if you don’t ask a good question. Whenever you ask a question, always provide concrete, copy and pasted information about code you’re running and errors you are receiving.

2 Likes

Sorry that was stupid.

Here is the complete log.

===> Compiling lz4
make: Entering directory '/var/www/diamond_web/deps/lz4/c_src'
cc /var/www/diamond_web/deps/lz4/c_src/lz4hc.o /var/www/diamond_web/deps/lz4/c_src/lz4_nif.o /var/www/diamond_web/deps/lz4/c_src/lz4.o -shared -L /usr/local/lib/erlang/lib/erl_interface-3.11.3/lib -lerl_interface -lei -o /var/www/diamond_web/deps/lz4/c_src/../priv/lz4.so
/var/www/diamond_web/deps/lz4/c_src/lz4hc.o: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status
make: *** [Makefile:58: /var/www/diamond_web/deps/lz4/c_src/../priv/lz4.so] Error 1
make: Leaving directory '/var/www/diamond_web/deps/lz4/c_src'
===> Hook for compile failed!

** (Mix) Could not compile dependency :lz4, "/home/www-data/.mix/rebar3 bare compile --paths "/var/www/diamond_web/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile lz4", update it with "mix deps.update lz4" or clean it with "mix deps.clean lz4"

You have copied whole directory with project to the remote host by the chance? Together with deps/ and _build/ directories?

No,
We just push the code using jenkins and run mix deps.get and other commands through dockerfile if you meant that.

The new error I am getting now is

2020-11-20 09:34:24.960241 crash_report        #{label=>{proc_lib,crash},report=>[[{initial_call,{supervisor,kernel,['Argument__1']}},{pid,<0.2023.0>},{registered_name,[]},{error_info,{exit,{on_load_function_failed,lz4},[{init,run_on_load_handlers,0,[]},{kernel,init,1,[{file,"kernel.erl"},{line,212}]},{supervisor,init,1,[{file,"supervisor.erl"},{line,295}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}},{ancestors,[kernel_sup,<0.1997.0>]},{message_queue_len,0},{messages,[]},{links,[<0.1999.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,376},{stack_size,27},{reductions,265}],[]]}
2020-11-20 09:34:24.960298 supervisor_report   #{label=>{supervisor,start_error},report=>[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,{on_load_function_failed,lz4}},{offender,[{pid,undefined},{id,kernel_safe_sup},{mfargs,{supervisor,start_link,[{local,kernel_safe_sup},kernel,safe]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}
2020-11-20 09:34:25.965749 crash_report        #{label=>{proc_lib,crash},report=>[[{initial_call,{application_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,<0.1996.0>},{registered_name,[]},{error_info,{exit,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,lz4}}},{kernel,start,[normal,[]]}},[{application_master,init,4,[{file,"application_master.erl"},{line,138}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}},{ancestors,[<0.1995.0>]},{message_queue_len,1},{messages,[{'EXIT',<0.1997.0>,normal}]},{links,[<0.1995.0>,<0.1994.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,610},{stack_size,27},{reductions,193}],[]]}
2020-11-20 09:34:25.969655 std_info            #{label=>{application_controller,exit},report=>[{application,kernel},{exited,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,lz4}}},{kernel,start,[normal,[]]}}},{type,permanent}]}
{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,lz4}}},{kernel,start,[normal,[]]}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,lz4}}},{kernel,start,[normal,[]]}}})

Crash dump is being written to: erl_crash.dump...done

That last error is that the nif can’t be loaded because it wasn’t built. Try removing the build artifacts for lz4, and rebuild. Something is wrong here: /var/www/diamond_web/deps/lz4/c_src/lz4hc.o: file not recognized: file format not recognized, did you build this on the machine you’re deploying to, or locally and then pushed up the artifacts?
Edit, just saw this was done through a dockerfile.

Do you have _build and deps in .dockerignore? Because if you have different OS on the Docker host then it may copy object files in wrong format.

1 Like