MickeyOoh

MickeyOoh

Undefined error of "enif_make_string" happens to erlang nif function

I am checking Nif function following Erlang erl_nif document and having an issue of compile error.
Could you please help me to solve this issue?

/* niftest.c */
#include <erl_nif.h>
static ERL_NIF_TERM hello(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
      { return enif_make_string(env, "Hello world!", ERL_NIF_LATIN1); }
static ErlNifFunc nif_funcs[] = { {"hello", 0, hello} };
ERL_NIF_INIT(niftest,nif_funcs,NULL,NULL,NULL,NULL)

compiling

$> gcc -fPIC -shared -o niftest.so niftest.c -I $ERL_ROOT/usr/include/
Undefined symbols for architecture x86_64:
 “_enif_make_string”, referenced from:
   _hello in niftest-cb9456.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

machine: macOS Monetery
gcc: Apple clang version 13.1.6 (clang-1316.0.21.2)
erlang: 24.3
include file: ERL_ROOT=~/.asdf/installs/erlang/24.3

It is where undefined symbol “enif_make_string” is defined.
erl_nif_api_funcs.h

#ifdef ERL_NIF_API_FUNC_DECL
  ERL_NIF_API_FUNC_DECL(
      ERL_NIF_TERM,
      enif_make_string,
      (ErlNifEnv* env, const char* string, ErlNifCharEncoding)
  );
#endif

#ifdef ERL_NIF_API_FUNC_MACRO
    #define enif_make_string ERL_NIF_API_FUNC_MACRO(enif_make_string)
#endif

The following is where two switching Macros is defined.
ERL_NIF_API_FUNC_DECL, ERL_NIF_API_FUNC_MACRO
erl_nif.h

#if (defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_))
  #define ERL_NIF_API_FUNC_DECL(RET_TYPE, NAME, ARGS) RET_TYPE (*NAME) ARGS typedef struct {
    #include "erl_nif_api_funcs.h"
    void* erts_alc_test;
  } TWinDynNifCallbacks;
  extern TWinDynNifCallbacks WinDynNifCallbacks;
  #undef ERL_NIF_API_FUNC_DECL
#endif
#if (defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_)) 
        && !defined(STATIC_ERLANG_DRIVER) && !defined(STATIC_ERLANG_NIF)
  #define ERL_NIF_API_FUNC_MACRO(NAME) (WinDynNifCallbacks.NAME)
  #include "erl_nif_api_funcs.h"
  /* note that we have to keep ERL_NIF_API_FUNC_MACRO defined */
#else /* non windows or included from emulator itself */
  #define ERL_NIF_API_FUNC_DECL(RET_TYPE, NAME, ARGS) extern RET_TYPE NAME ARGS
  #include "erl_nif_api_funcs.h"
  #undef ERL_NIF_API_FUNC_DECL
#endif

I couldn’t find switching macros of “__WIN32__” anywhere although this looks WindowsOS macro.

This issue happened on Erlang 23.x and I installed 24.3. So installation doesn’t cause this.

Please help me to find what I am missing.
Thanks.

Marked As Solved

garazdawi

garazdawi

Erlang Core Team

After checking again I think the -bundle is supposed to replace the -shared for clang. Does that work for you?

Also Liked

garazdawi

garazdawi

Erlang Core Team

On MacOS you also need to pass -bundle -bundle_loader $ERL_ROOT/erts-*/bin/beam.smp to gcc/clang in order for it to work.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement