Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module can't be loaded on Windows #29

Closed
Shemeikka opened this issue Oct 25, 2015 · 11 comments
Closed

Module can't be loaded on Windows #29

Shemeikka opened this issue Oct 25, 2015 · 11 comments

Comments

@Shemeikka
Copy link

I'm having trouble getting esqlite to compile on Windows 10

I get two different error messages depending on how I try to compile it.
Either

1> erlang:load_nif("esqlite3_nif", 0).
{error,{bad_lib,"Library module name 'esqlite3_nif' does not match calling module 'erl_eval'"}}

Or

 1> erlang:load_nif("./esqlite3_nif", 0).
 {error,{load_failed,"Failed to load NIF library ./esqlite3_nif: 'Unspecified error'"}}

This started when I created a new phoenix app using sqlite as a database.

mix phoenix.new webend --database sqlite

but that failed since compiling esqlite failed. Compiler cl.exe was not found in path but luckily I had Visual Studio installed on my computer so I just added the bin-folder to path. After trying again to compile esqlite using

mix deps.compile esqlite

it failed again. This time it couldn't find some files if I remember right. I installed proper rebar and added that to my path. Again tried to compile and it still failed. Then I started developer command prompt for visual studio and tried to compile esqlite again. This time it worked.

But loading the module will fail with unspecified error or not matching calling module 'erl_eval'.

I tried with following combinations:
cl.exe from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
cl.exe from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86
cl.exe from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64
and several VS2015 * tools command prompts

Compiling esqlite will give lots of warnings but it will always compile. The module just can't be loaded.

I'm using
Erlang/OTP 18 [erts-7.0] [64-bit] [smp:12:12] [async-threads:10]
Eshell V7.0 (abort with ^G)
esqlite 0.2.1
Windows 10 64bit ENG
Visual Studio 2015

@Shemeikka
Copy link
Author

Yeah,

It turned out that you can't load nif modules using shell. It will give you this error that I was seeing:

{error,{bad_lib,"Library module name 'esqlite3_nif' does not match calling module 'erl_eval'"}}

When using properly, the compiled module will work.

Build steps:
Added C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86 to path
Installed rebar (not the mix.local_rebar, though it might work with it)
Used VS2015 x64 Native Tools Command Prompt
Run rebar clean on esqlite-folder
Run rebar compile on esqlite-folder

I think everything works now, though I haven't tested anything expect loading.

@mmzeeman
Copy link
Owner

Then it is probably a path setting which is wrong. Unfortunately I don't have a windows box close by, so it is a bit hard to look into for me right now.

@davidspiess
Copy link

Same problem here. When i try to compile it with mix i get the following error message

$ mix deps.compile esqlite
==> esqlite (compile)
Compiled src/esqlite3_nif.erl
Compiled src/esqlite3.erl
Compiling c_src/esqlite3_nif.c
"cl.exe" is not recognized as an internal or external command,
operable program or batch file.
ERROR: compile failed while processing c:/Users/David/Dropbox/elixir/helloplug/deps/esqlite: rebar_abort
** (Mix) Could not compile dependency :esqlite, "escript.exe "c:/Users/David/.mix/rebar" compile skip_deps=true deps_dir="c:/Users/David/Dropbox/elixir/helloplug/_build/dev/lib"" command failed. You can recompile this dependency with "mix deps.compile esqlite", update it with "mix deps.update esqlite" or clean it with "mix deps.clean esqlite"

Maybe this additional informations from another user can help
https://groups.google.com/forum/#!topic/phoenix-talk/bPbpDDw3pMM

@mmzeeman
Copy link
Owner

It means that you have not setup your ms toolchain correctly. This might help you fix this:

https://msdn.microsoft.com/en-us/library/f2ccy3wt(v=VS.90).aspx

@pinx
Copy link

pinx commented Nov 21, 2016

Ran into the exact same problems. Would be good to have some hints in the README about this issue, and how to get sqlite working in Windows.

@mmzeeman
Copy link
Owner

Good idea.

@anil28
Copy link

anil28 commented Dec 25, 2016

Solved this issue with the below steps

from the command line type

mix local.rebar

then

goto C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC vcvarsall.bat amd64(type this at the end in the command line) and press enter

go back to your project folder and type "mix"

Now esqlite get compiled

@x-ji
Copy link

x-ji commented Dec 11, 2018

I'm not sure if I completely got how you solved it. Do you mean that the compilation itself is fine, but the the way the compiled module is loaded is wrong? I wonder what you did to fix the loading.

I'm trying to use sqlite in my Phoenix project with https://github.com/Sqlite-Ecto/sqlite_ecto2. The project works fine on Linux or Mac but when I try to compile it on Windows I get the same error.

00:23:56.322 [error] GenServer #PID<0.1379.0> terminating
** (RuntimeError) Connect raised a MatchError error. The exception details are hidden, as
they may contain sensitive data such as database credentials.

    (sqlite_ecto2) lib/sqlite_db_connection/protocol.ex:16: Sqlite.DbConnection.Protocol.connect/1
    (db_connection) lib/db_connection/connection.ex:135: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
00:23:56.369 [error] Process #PID<0.1386.0> raised an exception
** (MatchError) no match of right hand side value: {:error, {:load_failed, 'Failed to load NIF library c:/Users/JX/Desktop/BABE/_build/local/lib/esqlite/priv/esqlite3_nif: \'Unspecified error\''}}
    (esqlite) c:/Users/JX/Desktop/BABE/deps/esqlite/src/esqlite3_nif.erl:48: :esqlite3_nif.init/0
    (kernel) code_server.erl:1340: anonymous fn/1 in :code_server.handle_on_load/5
00:23:56.369 [warn] The on_load function for module esqlite3_nif returned:
{{:badmatch, {:error, {:load_failed, 'Failed to load NIF library c:/Users/JX/Desktop/BABE/_build/local/lib/esqlite/priv/esqlite3_nif: \'Unspecified error\''}}}, [{:esqlite3_nif, :init, 0, [file: 'c:/Users/JX/Desktop/BABE/deps/esqlite/src/esqlite3_nif.erl', line: 48]}, {:code_server, :"-handle_on_load/5-fun-0-", 1, [file: 'code_server.erl', line: 1340]}]}

Versions:

  • esqlite 0.2.5
  • Visual Studio 2017 Build Tools
  • sqlite_ecto2: 2.3.1

Is it the case that specifically the "amd64" version of the compiler will have to be used? Or is it just something specific to each system.

@mmzeeman
Copy link
Owner

That is an error message of the C compiler.

From what I remember from my windows dev days is that you have to run a bat files named like "vscvars.bat" or something similar. It will put the location of the standard include files in your environment.

@x-ji
Copy link

x-ji commented Dec 12, 2018 via email

@Shemeikka
Copy link
Author

@x-ji: How did you build the esqlite?

Can't remember exactly what I did back then but from my last comment it seems that I did following things:

  • Added C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86 to path though I believe newer versions should work just as well. You need to use amd64_x86 version if you are using 64bit Windows and mostly likely you are.
  • Installed rebar from their website. I might have just downloaded the binary file to the esqlite-folder under elixir project's build-folder. This folder path might be something like your_project_folder/_build/local/lib/esqlite
  • Opened VS2015 x64 Native Tools Command Prompt but newer versions should work just as well.
  • Navigated to the esqlite-folder, something like your_project_folder/_build/local/lib/esqlite
  • Run rebar clean
  • Run rebar compile

After these steps esqlite was compiled successfully and I could load it in iex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants