elixir-sqlite / exqlite

An SQLite3 driver for Elixir
https://hexdocs.pm/exqlite
MIT License
217 stars 48 forks source link

Getting `erl_nif_api_funcs.h: error: undeclared here (not in a function)` when compiling in MinGW #233

Closed hochata closed 1 year ago

hochata commented 1 year ago

Hi!

I've been trying to compile under Windows using MinGW, but I can't get past this error.

$ MAKE=make mix compile
==> exqlite
 CC sqlite3_nif.o
In file included from c_src/sqlite3_nif.c:10:
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:34:81: error: 'enif_free' undeclared here (not in a function)
   34 | ERL_NIF_API_FUNC_DECL(void*,enif_alloc,(size_t size) ERL_NAPI_ATTR_MALLOC_USD(1,enif_free,1));
      |                                                                                 ^~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif.h:329:72: note: in definition of macro 'ERL_NIF_API_FUNC_DECL'
  329 | #  define ERL_NIF_API_FUNC_DECL(RET_TYPE, NAME, ARGS) RET_TYPE (*NAME) ARGS
      |                                                                        ^~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_drv_nif.h:221:8: note: in expansion of macro 'ERL_NAPI_ATTR_MALLOC_D'
  221 |        ERL_NAPI_ATTR_MALLOC_D(DTOR, PTRPOS)
      |        ^~~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:34:54: note: in expansion of macro 'ERL_NAPI_ATTR_MALLOC_USD'
   34 | ERL_NIF_API_FUNC_DECL(void*,enif_alloc,(size_t size) ERL_NAPI_ATTR_MALLOC_USD(1,enif_free,1));
      |                                                      ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif.h:331:
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:34:1: warning: 'malloc' attribute ignored; valid only for function
s [-Wattributes]
   34 | ERL_NIF_API_FUNC_DECL(void*,enif_alloc,(size_t size) ERL_NAPI_ATTR_MALLOC_USD(1,enif_free,1));
      | ^~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:34:1: warning: 'malloc' attribute ignored; valid only for function
s [-Wattributes]
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:63:90: error: 'enif_mutex_destroy' undeclared here (not in a funct
ion)
   63 | ERL_NIF_API_FUNC_DECL(ErlNifMutex*,enif_mutex_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_mutex_destroy,1));
      |                                                                                          ^~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif.h:329:72: note: in definition of macro 'ERL_NIF_API_FUNC_DECL'
  329 | #  define ERL_NIF_API_FUNC_DECL(RET_TYPE, NAME, ARGS) RET_TYPE (*NAME) ARGS
      |                                                                        ^~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:63:67: note: in expansion of macro 'ERL_NAPI_ATTR_MALLOC_D'
   63 | ERL_NIF_API_FUNC_DECL(ErlNifMutex*,enif_mutex_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_mutex_destroy,1));
      |                                                                   ^~~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:63:1: warning: 'malloc' attribute ignored; valid only for function
s [-Wattributes]
   63 | ERL_NIF_API_FUNC_DECL(ErlNifMutex*,enif_mutex_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_mutex_destroy,1));
      | ^~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:68:88: error: 'enif_cond_destroy' undeclared here (not in a functi
on)
   68 | ERL_NIF_API_FUNC_DECL(ErlNifCond*,enif_cond_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_cond_destroy,1));
      |                                                                                        ^~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif.h:329:72: note: in definition of macro 'ERL_NIF_API_FUNC_DECL'
  329 | #  define ERL_NIF_API_FUNC_DECL(RET_TYPE, NAME, ARGS) RET_TYPE (*NAME) ARGS
      |                                                                        ^~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:68:65: note: in expansion of macro 'ERL_NAPI_ATTR_MALLOC_D'
   68 | ERL_NIF_API_FUNC_DECL(ErlNifCond*,enif_cond_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_cond_destroy,1));
      |                                                                 ^~~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:68:1: warning: 'malloc' attribute ignored; valid only for function
s [-Wattributes]
   68 | ERL_NIF_API_FUNC_DECL(ErlNifCond*,enif_cond_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_cond_destroy,1));
      | ^~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:73:92: error: 'enif_rwlock_destroy' undeclared here (not in a func
tion)
   73 | ERL_NIF_API_FUNC_DECL(ErlNifRWLock*,enif_rwlock_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_rwlock_destroy,1));
      |                                                                                            ^~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif.h:329:72: note: in definition of macro 'ERL_NIF_API_FUNC_DECL'
  329 | #  define ERL_NIF_API_FUNC_DECL(RET_TYPE, NAME, ARGS) RET_TYPE (*NAME) ARGS
      |                                                                        ^~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:73:69: note: in expansion of macro 'ERL_NAPI_ATTR_MALLOC_D'
   73 | ERL_NIF_API_FUNC_DECL(ErlNifRWLock*,enif_rwlock_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_rwlock_destroy,1));
      |                                                                     ^~~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:73:1: warning: 'malloc' attribute ignored; valid only for function
s [-Wattributes]
   73 | ERL_NIF_API_FUNC_DECL(ErlNifRWLock*,enif_rwlock_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_rwlock_destroy,1));
      | ^~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:85:101: error: 'enif_thread_opts_destroy' undeclared here (not in
a function)
   85 | ERL_NIF_API_FUNC_DECL(ErlNifThreadOpts*,enif_thread_opts_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_thread_opts_destroy,1
));
      |                                                                                                     ^~~~~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif.h:329:72: note: in definition of macro 'ERL_NIF_API_FUNC_DECL'
  329 | #  define ERL_NIF_API_FUNC_DECL(RET_TYPE, NAME, ARGS) RET_TYPE (*NAME) ARGS
      |                                                                        ^~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:85:78: note: in expansion of macro 'ERL_NAPI_ATTR_MALLOC_D'
   85 | ERL_NIF_API_FUNC_DECL(ErlNifThreadOpts*,enif_thread_opts_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_thread_opts_destroy,1
));
      |                                                                              ^~~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:85:1: warning: 'malloc' attribute ignored; valid only for function
s [-Wattributes]
   85 | ERL_NIF_API_FUNC_DECL(ErlNifThreadOpts*,enif_thread_opts_create,(char *name) ERL_NAPI_ATTR_MALLOC_D(enif_thread_opts_destroy,1
));
      | ^~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:111:1: warning: 'malloc' attribute ignored; valid only for functio
ns [-Wattributes]
  111 | ERL_NIF_API_FUNC_DECL(void *, enif_alloc_resource, (ErlNifResourceType *type, size_t size) ERL_NAPI_ATTR_MALLOC_US(2));
      | ^~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:187:103: error: 'enif_ioq_destroy' undeclared here (not in a funct
ion)
  187 | ERL_NIF_API_FUNC_DECL(ErlNifIOQueue *,enif_ioq_create,(ErlNifIOQueueOpts opts) ERL_NAPI_ATTR_MALLOC_D(enif_ioq_destroy,1));
      |                                                                                                       ^~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif.h:329:72: note: in definition of macro 'ERL_NIF_API_FUNC_DECL'
  329 | #  define ERL_NIF_API_FUNC_DECL(RET_TYPE, NAME, ARGS) RET_TYPE (*NAME) ARGS
      |                                                                        ^~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:187:80: note: in expansion of macro 'ERL_NAPI_ATTR_MALLOC_D'
  187 | ERL_NIF_API_FUNC_DECL(ErlNifIOQueue *,enif_ioq_create,(ErlNifIOQueueOpts opts) ERL_NAPI_ATTR_MALLOC_D(enif_ioq_destroy,1));
      |                                                                                ^~~~~~~~~~~~~~~~~~~~~~
c:/Program Files/Erlang OTP/erts-13.1.4/include/erl_nif_api_funcs.h:187:1: warning: 'malloc' attribute ignored; valid only for functio
ns [-Wattributes]
  187 | ERL_NIF_API_FUNC_DECL(ErlNifIOQueue *,enif_ioq_create,(ErlNifIOQueueOpts opts) ERL_NAPI_ATTR_MALLOC_D(enif_ioq_destroy,1));
      | ^~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:134: c:/msys64/home/Propietario/repos/exqlite/_build/dev/lib/exqlite/obj/sqlite3_nif.o] Error 1
** (Mix) Could not compile with "make" (exit status: 2).

All the errors complain about undeclared objects in erl_nif_api_funcs.h.

This is my current installation

$ elixir --version
Erlang/OTP 25 [erts-13.1.4] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

Elixir 1.14.3 (compiled with Erlang/OTP 25)

I'm not sure if it is a bug in Exqlite or I just haven't installed the right environment. I followed the instructions from Elixir Make to install an appropirate C toolchain.

Any idea about how to fix it? Or how could I debug it?

warmwaffles commented 1 year ago

This sounds like an issue with your toolchain setup. @voltagex may be able to help out here.

voltagex commented 1 year ago

This sounds like an issue with your toolchain setup. @voltagex may be able to help out here.

Sorry, I used MSVC, not MinGW.

voltagex commented 1 year ago

Agree it seems like a toolchain problem, though.

hochata commented 1 year ago

Ok, I'll check my installation. Thanks for the tips!

warmwaffles commented 1 year ago

@hochata we added pre-compilation support now. You may not even need the full toolchain.

hochata commented 1 year ago

Mmm, it very likely will solve my problem. I will check it out. Thanks!

warmwaffles commented 1 year ago

No problem, feel free to comment if it does not.