Answer the question
In order to leave comments, you need to log in
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)
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question