Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++: How to unmangle exported symbols

I'm trying to compile a Java library that uses JNI. When I start the program, I see a crash with an UnsatisfiedLinkError, which says that a particular method could not be found in the DLL.

On closer inspection, I found out that g++, which I use for compilation and linking, mangled my method names by adding suffixes such as "@8" or "@16" to the method names. Does anybody know the correct compiler options to disable the name mangling? Thanks in advance!

EDIT: I'm using MinGW through Eclipse + CDT plugin.

like image 358
python dude Avatar asked Jan 02 '10 20:01

python dude


People also ask

What are exported symbols?

Exporting a symbol means "advertising" its existence in your object file/library and where it is, so that it could be imported (=linked to) by other modules.

How do I find the symbol in an .so file?

The flag -g is used to show only exported symbols. Show activity on this post. Try adding -l to the nm flags in order to get the source of each symbol. If the library is compiled with debugging info (gcc -g) this should be the source file and line number.


1 Answers

For JNI calls to work with Windows DLLs compiled with GCC you need to add a add-stdcall-alias parameter to GCC on linking phase:

gcc -Wl,--add-stdcall-alias

Which will add correct function names to the DLL and thus enable calls via JNI.

like image 184
Mavrik Avatar answered Sep 24 '22 01:09

Mavrik