[erlang-questions] problem when use g++ to compile erl_nif

Sverker Eriksson sverker@REDACTED
Tue Mar 30 18:06:26 CEST 2010


@caox:
The important thing is that both #include "erl_nif.h" and ERL_NIF_INIT 
are within export "C" {}.
I will put some #ifdef __cplusplus in erl_nif.h for next release to make 
it more convenient for C++ users.

By your compile error, it looks like you are running R13B03. I would 
recommend R13B04, even though you might get that to work with some 
(void*) casting at the right place.

@Dave:
Nice bloom filter. A performance tip is to do enif_make_atom's and store 
in static variables at load. Atom terms are allowed to be kept between 
calls.

/Sverker, Erlang/OTP Ericsson


Dave Smith wrote:
> Take a look at the ebloom project:
>
> http://hg.basho.com/ebloom/
>
> That's a NIF which wraps a C++ header-style bloom filter.
>
> Bottom line, you need to include erl_nif.h in a separate header and
> then make sure that all the stuff required by erlang happens in a
> extern "C" section.
>
> D.
>
> On Tue, Mar 30, 2010 at 12:34 AM, caox <caox@REDACTED> wrote:
>   
>> I am trying to use erl_nif to implement some drivers.And I am wondering if
>> there is any way to compile  nif files with g++, just like what
>>
>> #ifdef __cplusplus
>> extern "C" { // shouldn't this be in the DRIVER_INIT macro?
>> #endif
>> DRIVER_INIT(template_drv) {
>>    return &template_drv_entry;
>> }
>> #ifdef __cplusplus
>> }
>> #endif
>>
>> can do for erl_driver. In that way, it will be more convenient to code with
>> c++ libs.
>> But now, I got an error when using g++ to run the example with OTPR1303:
>>
>> g++ -shared -fpic -ldl -I/usr/lib64/erlang/usr/include -I/usr/include
>> -I/usr/lib64/erlang/lib/erl_interface-3.6.4/include
>> -I/mnt/hgfs/work/ewp_new_trunk/drivers/template
>> -I/mnt/hgfs/work/vendor/clearsilver-0.10.5 -o ./priv/niftest.so
>> c_src/niftest.c -L/usr/lib64/erlang/lib/erl_interface-3.6.4/lib
>> -L/usr/lib64/erlang/usr/lib -lei -lxerces-c   -lxqilla
>>  -L/mnt/hgfs/work/vendor/clearsilver-0.10.5/libs -lneo_cs -lneo_cgi
>> -lneo_utl
>> c_src/niftest.c:28: error: invalid conversion from ‘ERL_NIF_TERM
>> (*)(ErlNifEnv*)’ to ‘void*’
>> make: *** [nif] Er/
>>
>> Appreciate your help.
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>>
>>
>>     
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>
>   




More information about the erlang-questions mailing list