N
N
nuclear_kote2018-06-19 14:47:00
Java
nuclear_kote, 2018-06-19 14:47:00

Why doesn't jna find a function in compiled g++?

In general, there is such an article:
https://habr.com/post/113436/
when I do everything according to the instructions, everything works, but if I change gcc to g++, I get something like this:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'registerCallback': /root/tmp/libmy.so: undefined symbol: registerCallback
  at com.sun.jna.Function.<init>(Function.java:245)
  at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:566)
  at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:542)
  at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:528)
  at com.sun.jna.Library$Handler.invoke(Library.java:228)
  at com.sun.proxy.$Proxy0.registerCallback(Unknown Source)
  at com.test.Test.main(Test.java:14)

how to build under g++?
UPD:
objdump -x shows that after build g++ the method is called _Z16registerCallbackPFvPcS_E
and in gcc just registerCallback

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2018-06-19
@nuclear_kote

This is because when you call g++ other default settings are used, by default your code is considered C++ code (even files with extension .c, see https://stackoverflow.com/questions/172587/what-is... ) and, accordingly , name mangling starts working . Options:
- use extern "C" for registerCallback;
- Compile code as C code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question