简体   繁体   English

使用 -lstdc++ 时,Clang++ 确实会命名重整,尽管有 extern "C"

[英]Clang++ does name mangling inspite of extern "C" when using -lstdc++

I build a shared-object using Clang++.我使用 Clang++ 构建了一个共享对象。 The major functions are located in 'extern "C"' block.主要功能位于'extern "C"' 块中。 The building is fine, and I can call these functions using JNA.建筑物很好,我可以使用 JNA 调用这些函数。

When I added the flag "-lstdc++" (for using some C++11 features) - I got runtime error:当我添加标志“-lstdc++”(用于使用某些 C++11 功能)时 - 我收到运行时错误:

undefined symbol: _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm

I run我跑

nm target/classes/linux-x86-64/libCloudCryptoLibrary.so  |grep init

then I get然后我得到

                 U _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm
                 U _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEmc
0000000000004860 T _init
0000000000024360 T init

When I remove that flag, and run nm again, I get:当我删除该标志并再次运行 nm 时,我得到:

                 U _ZNKSt5ctypeIcE13_M_widen_initEv@@GLIBCXX_3.4.11
000000000026b920 b _ZStL8__ioinit
000000000026b9e0 b _ZStL8__ioinit
0000000000004508 T _init
0000000000021000 T init

What can I do for correct it?我能做些什么来纠正它?

I found a solution: I have a function named "init" in the extern "C" block (as you can see the line "0000000000021000 T init").我找到了一个解决方案:我在 extern "C" 块中有一个名为 "init" 的函数(如您所见的行“0000000000021000 T init”)。 I renamed it to "initMyClass" and the problem disappear.我将它重命名为“initMyClass”,问题就消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM