You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.so库导出函数不可见:_Z20符号含义及问题排查

Understanding the Mangled Symbol and Fixing the Missing Function Issue

Hey there! Let's unpack what's happening with your .so library and the missing function issue step by step.

First: What does T _Z20... mean?

Let's break down the nm output you got:

  • The T indicates that this symbol is a global function located in the text (code) section of the library—so it is exported, just not in the format your client expects.
  • The _Z20aaasPP8CashInfoPiS1_S2_S2_PcS3_ part is C++ name mangling. C++ compilers do this to handle function overloading (since multiple functions can share the same name but have different parameters) and other C++ language features. The mangled string encodes both the function name and its parameter types:
    • _Z: A standard prefix marking this as a mangled C++ symbol.
    • 20: The total length of the following function name and parameter type encoding (this number counts every character that comes after it in the symbol).
    • aaa: Your original function name.
    • The trailing sequence (sPP8CashInfoPiS1_S2_S2_PcS3_) encodes the parameter types of your function (for example, P means pointer, i stands for int, CashInfo refers to your struct type, etc.).

Why isn't the new function visible to the client?

The core problem is a linkage mismatch between your new function and the client's lookup logic:

  • Your other visible functions are almost certainly exported using C linkage, which skips name mangling. That's why their nm output shows plain, human-readable function names instead of mangled strings.
  • Your new aaa function is a C++ function without extern "C" decoration, so the compiler applied C++ name mangling. When the client tries to look up the plain name aaa, it can't match the mangled _Z20aaas... symbol that's actually exported.

How to fix this?

The simplest and most portable fix is to force C linkage for the function so the compiler skips name mangling. Add extern "C" to the function declaration in your library's header file:

extern "C" {
    // Declare your function here with its full, original signature
    void aaa(/* match your actual parameter types */);
}

This tells the C++ compiler to export the function using C-style naming. After rebuilding the library, nm -D libmylib.so |grep " T " |grep aaa will show T aaa instead of the mangled string, and your client will be able to find it just like the other functions.

内容的提问来源于stack exchange,提问作者vico

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:33:43