NIFS

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

NIFS

Karlo Kuna
i am using c++ to implement nif module 

now i can compile my project but on function call i get: 

Failed to load NIF library: my.so undefined symbol: _ZTVN10__cxxabiv117__class_type_infoE

can someone give me a hint what is this error?  is it linkage, or bad call, or something else 
and how go about solving it? 


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: NIFS

Stanislaw Klekot
On Sat, Feb 04, 2017 at 11:25:33PM +0100, Karlo Kuna wrote:

> i am using c++ to implement nif module
> and i am using nifpp (https://github.com/goertzenator/nifpp)
>
> now i can compile my project but on function call i get:
>
> Failed to load NIF library: my.so undefined symbol:
> _ZTVN10__cxxabiv117__class_type_infoE
>
> can someone give me a hint what is this error?  is it linkage, or bad call,
> or something else
> and how go about solving it?

It's because of name mangling by C++ compiler (necessary thing for
overloaded functions to work). It's a totally expected problem when
you're writing in C++ a library that needs to be used by system written
in C. You need to disable name mangling for your NIF function.

--
Stanislaw Klekot
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: NIFS

Karlo Kuna
now i'm getting:
undefined symbol: _ZNSt8ios_base4InitD1Ev 



On Sat, Feb 4, 2017 at 11:45 PM, Stanislaw Klekot <[hidden email]> wrote:
On Sat, Feb 04, 2017 at 11:25:33PM +0100, Karlo Kuna wrote:
> i am using c++ to implement nif module
> and i am using nifpp (https://github.com/goertzenator/nifpp)
>
> now i can compile my project but on function call i get:
>
> Failed to load NIF library: my.so undefined symbol:
> _ZTVN10__cxxabiv117__class_type_infoE
>
> can someone give me a hint what is this error?  is it linkage, or bad call,
> or something else
> and how go about solving it?

It's because of name mangling by C++ compiler (necessary thing for
overloaded functions to work). It's a totally expected problem when
you're writing in C++ a library that needs to be used by system written
in C. You need to disable name mangling for your NIF function.

--
Stanislaw Klekot


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: NIFS

Karlo Kuna
also 
ldd -r my.so
gives: 
undefined symbol: _ZNSt8ios_base4InitD1Ev
undefined symbol: enif_make_atom
undefined symbol: _ZNSt8ios_base4InitC1Ev 



On Sun, Feb 5, 2017 at 6:48 AM, Karlo Kuna <[hidden email]> wrote:
now i'm getting:
undefined symbol: _ZNSt8ios_base4InitD1Ev 



On Sat, Feb 4, 2017 at 11:45 PM, Stanislaw Klekot <[hidden email]> wrote:
On Sat, Feb 04, 2017 at 11:25:33PM +0100, Karlo Kuna wrote:
> i am using c++ to implement nif module
> and i am using nifpp (https://github.com/goertzenator/nifpp)
>
> now i can compile my project but on function call i get:
>
> Failed to load NIF library: my.so undefined symbol:
> _ZTVN10__cxxabiv117__class_type_infoE
>
> can someone give me a hint what is this error?  is it linkage, or bad call,
> or something else
> and how go about solving it?

It's because of name mangling by C++ compiler (necessary thing for
overloaded functions to work). It's a totally expected problem when
you're writing in C++ a library that needs to be used by system written
in C. You need to disable name mangling for your NIF function.

--
Stanislaw Klekot



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
zv
Reply | Threaded
Open this post in threaded view
|

Re: NIFS

zv
I'm not familiar with ~nifpp~ in particular, but if you are receiving an error like

> undefined symbol: enif_make_atom

There are underlying issues beyond symbol mangling.

I assume you are including erl_nif.h, directly or otherwise. As far as the mangling is concerned, you haven't made it clear if you are using objdump to extract the correct symbol name or if you are relying on the compiler, although Stanislaw has already mentioned the issue so you have a thread to follow.

If you are getting an 'undefined symbol' on function call, you are dynamically linking your library, which means you need to make sure that your library is on the linker path during runtime as that's how the dynamic library loader will find it (which happens when you load the nif in Erlang, it spiders out to the libraries that library needs until it can resolve all the required symbols).

An alternative approach would be to make your my.so a static library my.a and then link your nif against that which removes some of these issues in finding libraries.

You also might want to just consider an "extern C" linkage declaration, totally bypassing any mangling or other C++ symbol decoration idiosyncrasies.

- zephyr

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: NIFS

Karlo Kuna
problem is that i am already using "extern C" declaration, 

and as far as symbol names i'm relying on compiler 

so far i have noticed that some problems go away if i don't include some headers (iostream) and that's fine 
but now when i try to use std::string in nif implementation, when i call it i get:

{load_failed,"Failed to load NIF library: './priv/my.so: undefined symbol: __gxx_personality_v0'"

On Sun, Feb 5, 2017 at 9:01 AM, zv <[hidden email]> wrote:
I'm not familiar with ~nifpp~ in particular, but if you are receiving an error like

> undefined symbol: enif_make_atom

There are underlying issues beyond symbol mangling.

I assume you are including erl_nif.h, directly or otherwise. As far as the mangling is concerned, you haven't made it clear if you are using objdump to extract the correct symbol name or if you are relying on the compiler, although Stanislaw has already mentioned the issue so you have a thread to follow.

If you are getting an 'undefined symbol' on function call, you are dynamically linking your library, which means you need to make sure that your library is on the linker path during runtime as that's how the dynamic library loader will find it (which happens when you load the nif in Erlang, it spiders out to the libraries that library needs until it can resolve all the required symbols).

An alternative approach would be to make your my.so a static library my.a and then link your nif against that which removes some of these issues in finding libraries.

You also might want to just consider an "extern C" linkage declaration, totally bypassing any mangling or other C++ symbol decoration idiosyncrasies.

- zephyr

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: NIFS

Mikael Pettersson-5
In reply to this post by Karlo Kuna
Karlo Kuna writes:
 > also
 > ldd -r my.so
 > gives:
 > undefined symbol: _ZNSt8ios_base4InitD1Ev
 > undefined symbol: enif_make_atom
 > undefined symbol: _ZNSt8ios_base4InitC1Ev

The enif_make_atom one is expected; it will be satisfied by the VM itself
when you load the .so.

The others indicate that the dynamic linker is unable to find all external
shared libraries you depend on, in particular ones that should have come
from the system's C++ / libstdc++ installation.

Something's fishy with your system or your build/deploy procedures.

 >
 >
 >
 > On Sun, Feb 5, 2017 at 6:48 AM, Karlo Kuna <[hidden email]> wrote:
 >
 > > now i'm getting:
 > > undefined symbol: _ZNSt8ios_base4InitD1Ev
 > >
 > >
 > >
 > > On Sat, Feb 4, 2017 at 11:45 PM, Stanislaw Klekot <[hidden email]>
 > > wrote:
 > >
 > >> On Sat, Feb 04, 2017 at 11:25:33PM +0100, Karlo Kuna wrote:
 > >> > i am using c++ to implement nif module
 > >> > and i am using nifpp (https://github.com/goertzenator/nifpp)
 > >> >
 > >> > now i can compile my project but on function call i get:
 > >> >
 > >> > Failed to load NIF library: my.so undefined symbol:
 > >> > _ZTVN10__cxxabiv117__class_type_infoE
 > >> >
 > >> > can someone give me a hint what is this error?  is it linkage, or bad
 > >> call,
 > >> > or something else
 > >> > and how go about solving it?
 > >>
 > >> It's because of name mangling by C++ compiler (necessary thing for
 > >> overloaded functions to work). It's a totally expected problem when
 > >> you're writing in C++ a library that needs to be used by system written
 > >> in C. You need to disable name mangling for your NIF function.
 > >>
 > >> --
 > >> Stanislaw Klekot
 > >>
 > >
 > >
 >
 > ----------------------------------------------------------------------
 > _______________________________________________
 > erlang-questions mailing list
 > [hidden email]
 > http://erlang.org/mailman/listinfo/erlang-questions

--
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: NIFS

Karlo Kuna
For everyones amusement and information. I have overlooked something important as a noob and then some. 
Compiling and linking where done in two steps, and i have reused makefile form another project not realizing that 
linking step would be done by "cc" and that was the problem, changing it to for example g++ resolved my issue. 

This was one of those costly errors, when one stares at build output for very long time and not seeing things that are 
plainly there.  

thank you everyone for help

On Sun, Feb 5, 2017 at 11:11 AM, Mikael Pettersson <[hidden email]> wrote:
Karlo Kuna writes:
 > also
 > ldd -r my.so
 > gives:
 > undefined symbol: _ZNSt8ios_base4InitD1Ev
 > undefined symbol: enif_make_atom
 > undefined symbol: _ZNSt8ios_base4InitC1Ev

The enif_make_atom one is expected; it will be satisfied by the VM itself
when you load the .so.

The others indicate that the dynamic linker is unable to find all external
shared libraries you depend on, in particular ones that should have come
from the system's C++ / libstdc++ installation.

Something's fishy with your system or your build/deploy procedures.

 >
 >
 >
 > On Sun, Feb 5, 2017 at 6:48 AM, Karlo Kuna <[hidden email]> wrote:
 >
 > > now i'm getting:
 > > undefined symbol: _ZNSt8ios_base4InitD1Ev
 > >
 > >
 > >
 > > On Sat, Feb 4, 2017 at 11:45 PM, Stanislaw Klekot <[hidden email]>
 > > wrote:
 > >
 > >> On Sat, Feb 04, 2017 at 11:25:33PM +0100, Karlo Kuna wrote:
 > >> > i am using c++ to implement nif module
 > >> > and i am using nifpp (https://github.com/goertzenator/nifpp)
 > >> >
 > >> > now i can compile my project but on function call i get:
 > >> >
 > >> > Failed to load NIF library: my.so undefined symbol:
 > >> > _ZTVN10__cxxabiv117__class_type_infoE
 > >> >
 > >> > can someone give me a hint what is this error?  is it linkage, or bad
 > >> call,
 > >> > or something else
 > >> > and how go about solving it?
 > >>
 > >> It's because of name mangling by C++ compiler (necessary thing for
 > >> overloaded functions to work). It's a totally expected problem when
 > >> you're writing in C++ a library that needs to be used by system written
 > >> in C. You need to disable name mangling for your NIF function.
 > >>
 > >> --
 > >> Stanislaw Klekot
 > >>
 > >
 > >
 >
 > ----------------------------------------------------------------------
 > _______________________________________________
 > erlang-questions mailing list
 > [hidden email]
 > http://erlang.org/mailman/listinfo/erlang-questions

--


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions