Erlang bcrypt not compiling bcrypt_nif.so

512 views
Skip to first unread message

Justin Schneck

unread,
Aug 9, 2014, 8:16:37 PM8/9/14
to elixir-l...@googlegroups.com
I am trying to implement bcrypt to hash passwords in an elixir project. I am experiencing a similar problem to the post found here

Here is the issue

[error] The on_load function for module bcrypt_nif returned {:error,

{:load_failed, 'Failed to load NIF library: \'/opt/proj/db/proj_db/_build/test/lib/bcrypt/priv/bcrypt_nif.so: cannot open shared object file: No such file or directory\''}}


My Mix.esx

defmodule ProjectDb.Mixfile do
  use Mix.Project

  def project do
    [app: :project_db,
     version: "0.0.1",
     elixir: "~> 0.15.0",
     deps: deps]
  end

  def application do
    [applications: [:logger, :crypto, :bcrypt]]
  end

  defp deps do
    [
      {:ecto,      github: "elixir-lang/ecto"},
      {:poolboy,   github: "devinus/poolboy", override: true},
      {:postgrex,  github: "ericmj/postgrex", override: true},
      {:bcrypt,    github: "smarkets/erlang-bcrypt"}
    ]
  end
end

The output from bcrypt's compile
$ mix deps.compile

Compiled src/bcrypt_port_sup.erl

Compiled src/bcrypt_sup.erl

Compiled src/bcrypt_port.erl

Compiled src/bcrypt_nif.erl

Compiled src/bcrypt_nif_worker.erl

Compiled src/bcrypt_app.erl

Compiled src/bcrypt.erl

Compiled src/bcrypt_pool.erl

Compiling c_src/async_queue.c

Compiling c_src/bcrypt.c

Compiling c_src/bcrypt_nif.c

Compiling c_src/bcrypt_port.c

Compiling c_src/blowfish.c


When I search for bcrypt_nif.so it does not exist.

I am borderline thinking I have an issue with Erlang deps which use rebar? not sure. just guessing.


José Valim

unread,
Aug 9, 2014, 10:36:59 PM8/9/14
to elixir-l...@googlegroups.com
Can you see the _build/test/lib/bcrypt/priv/bcrypt_nif.so file?

If not, do you have a symlink from _build/test/lib/bcrypt/priv to deps/bcrypt/priv?

If not, I will investigate it first thing tomorrow.

José Valim
Skype: jv.ptec
Founder and Lead Developer


--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Akash Manohar

unread,
Aug 10, 2014, 10:50:35 AM8/10/14
to elixir-l...@googlegroups.com
Justin,

I would suggest doing the following:

1.) Use IRCcloud's fork of erlang-bcrypt - https://github.com/irccloud/erlang-bcrypt. I believe that's maintained because IRCcloud themselves use it (plus the "relatively" recent commit date)

2.) Use the port mechanism option for erlang-bcrypt. Add the following lines to your Elixir project's config/config.exs file.

# This line might already be there in your config file, so you can skip this
use Mix.Config

# Use port mechanism. Pool size is the number of workers it'll use.
config
:bcrypt, [mechanism: :port, pool_size: 4]


I've experienced problems with bcrypt NIF for a different reason tho (wasn't able to use it on low-ram machines like small VPS boxes). The above is what worked for me.

Justin Schneck

unread,
Aug 10, 2014, 11:04:33 AM8/10/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Hi checked on these and the answers are
inside _build/test/lib/bcrypt/priv/ is
bcrypt_drv.so and bcrypt

_build/test/lib/bcrypt/priv is symlinked to deps/bcrypt/priv

Justin Schneck

unread,
Aug 10, 2014, 11:15:45 AM8/10/14
to elixir-l...@googlegroups.com
Akash,

Unfortunately I am getting the same issue with icccloud's fork. I have also added the config changes you suggested to my config.exs. The weird thing is that I see it compiling bcrypt_nif.c in the output from mix but when I do a find for it after its nowhere. Is it getting overwritten when the sym-link happens?

Akash Manohar

unread,
Aug 10, 2014, 11:38:59 AM8/10/14
to elixir-l...@googlegroups.com
I think Jose or Eric can answer better about the symlink. I'm curious why the port doesn't work for you (because I've been using that with Heroku too for sometime now). Any error you get for that or any particular steps to reproduce?





--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-talk/FKbARTmC9Yw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-ta...@googlegroups.com.

José Valim

unread,
Aug 10, 2014, 11:46:19 AM8/10/14
to elixir-l...@googlegroups.com
I have tried locally and it doesn't work with symlinks nor with copying the script files. :(



José Valim
Skype: jv.ptec
Founder and Lead Developer


--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.

Akash Manohar

unread,
Aug 10, 2014, 12:44:49 PM8/10/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Justin,

That reminds me about how I got this library working. Just drop into the IRCcloud support channel. One of their devs will surely be hanging out there. You could take their help with getting this lib working.

I'm pretty sure they would suggest port mechanism.

Justin Schneck

unread,
Aug 10, 2014, 1:51:45 PM8/10/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
It appears that this problem is with the rebar.config. I applied pull request
and recompiled. seems to be functioning now. The version of rebar I am using is the one included with mix. Maybe there is something we could to do to that could check for incompatibility between the rebar.config and the version of rebar that mix includes? I am spitballing not suggesting that this is actually a mix bug per say.

Akash Manohar

unread,
Aug 10, 2014, 1:56:02 PM8/10/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Justin,

Ah yes, I forgot about this problem with erlang repos. Some erlang library repos ship rebar too. Beware of older erlang repos. I think this has to do something with how mix prioritizes which rebar to use (it's own version, rebar in library repo, etc)

José Valim

unread,
Aug 10, 2014, 1:58:07 PM8/10/14
to elixir-l...@googlegroups.com
Unfortunately there is no specification about which config is allowed by which rebar version. So I am not sure if there is something we can do.

We never use the local rebar version because they were often broken. So we will use the one in your path or the one installed by mix local.rebar.



José Valim
Skype: jv.ptec
Founder and Lead Developer


Justin Schneck

unread,
Aug 10, 2014, 3:23:03 PM8/10/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Just to sum up this post. I was able to get this working by doing the following.

mix.exs
def application do
  [applications: [:logger, :crypto, :bcrypt]]
end

defp deps do
  [
    {:ecto,      github: "elixir-lang/ecto"},
    {:poolboy,   github: "devinus/poolboy", override: true},
    {:postgrex,  github: "ericmj/postgrex", override: true},
    {:bcrypt,    github: "jwilberding/erlang-bcrypt", override: true}
  ]
end

config.exs
config :bcrypt, [mechanism: :port, pool_size: 4]

Thanks José and Akash

José Valim

unread,
Aug 10, 2014, 3:43:38 PM8/10/14
to elixir-l...@googlegroups.com
Curiosity, why are you using git repos instead of using hex? :)



José Valim
Skype: jv.ptec
Founder and Lead Developer


Justin Schneck

unread,
Aug 10, 2014, 5:22:18 PM8/10/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
I was following along to some code on Josh Adams sips.
https://github.com/knewter/beam_toolbox_data

I guess he needed bleeding edge for a reason. I changed back to using hex with no problems. Put a little "stability" back in my life :)

Josh Adams

unread,
Aug 11, 2014, 2:19:12 PM8/11/14
to elixir-l...@googlegroups.com, José Valim
And I haven't got the foggiest why *I'm* using github for those dependencies :)
Josh Adams
Reply all
Reply to author
Forward
0 new messages