2025-07-06 11:18:03 -07:00

10 lines
906 B
Markdown

To list every symbol in a dll, use "nm".
"nm -g hello.so" output "T square", where hello.so is created from a **C** source file containing function square.
"nm -g callee.so" output "T \_Z7isprimex", "_Z9sumprimesx", where callee.so is created from a **C++** file containing function isprime and sumprimes.
Why does the names differ? C++ compilers use "name mangling" to support overloading, etc, resulting in names that differ from names in the source file. This is not done in C compilers (since C does not support overloading as well).
To prevent name mangling, use `extern "C"` directive in the function declaration.
The extern keyword may be applied to a global variable, function, or template declaration. It specifies that the symbol has external linkage.
`extern "C"` specifies that the function is defined elsewhere and uses the C-language calling convention, which includes do not mangle names.