0

I try to load a dynamic library with dlopen. The code in the lib should call a function inside the executeable (compiled with flag -rdynamic).

dlopen gives this error:

undefined symbol: 
_Z10vGnssTraceNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEhS4_

If I look at the exported symbols of my executeable with nm, I see this:

0004b779 T    _Z10vGnssTraceNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEhS4_

And the result of nm for the lib is this:

         U _Z10vGnssTraceNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEhS4_

Looks like it should match!? How can I make the lib know the function in the executeable?

According to this https://stackoverflow.com/a/17083153/10551203 it should work.

Any help would be highly appreciated

Ralf

  • I think the difference is `_` at beginnig. I don't remember why/when this is added exactly, but you can try to look into it. (I think it has something to do with __cdecl, but not sure.) – sklott Sep 17 '20 at 11:08
  • These look identical and should work. How exactly do you build the shared library? Can you create a [mcve]? – n. m. could be an AI Sep 20 '20 at 11:17

1 Answers1

0

Hello and thanks to everybody who looked at this. Now, after a few days, I know more about the topic and my real problem was completely different, compared to what I expected.

I inspected my executable with nm to see the exported symbols but I didn't use the -D option. Even after I knew it exists, I wasn't sure, if I need it or if it's only applicable for the dynamic lib. In fact, the symbols of the executable were not exported at all.

I use autotools and added the -rdynamic to the AM_LDFLAGS. But the Makefile.am is long and there is another *_LDFLAGS section especially for the executeable, that I wasn't aware of. Because of this, the AM_LDFLAGS were not applied when linking, which is expected, see the AM_LDFLAGS section of https://www.gnu.org/software/automake/manual/html_node/Program-Variables.html : In some situations, this is not used, in preference to the per-executable (or per-library) _LDFLAGS.

Best regards Ralf