在Android adb shell本机程序中使用stl

发布于 01-02 12:02 字数 792 浏览 2 评论 0原文

我正在尝试移植一个我想从 Android ADB shell 运行的 C++ 实用程序。 为此,我使用 Android NDK 的 make-standalone-toolchain.sh 脚本,并用它编译我的程序。 不幸的是,当我尝试运行它时,出现此错误:

reloc_library[1315]: 16304 cannot locate '_ZNKSs5c_strEv'...
CANNOT LINK EXECUTABLE

经过一番研究,我发现这意味着 NDK 中的 libstdc++.so 中不存在 c_str 函数。我也无法在 stlport.so 中找到该符号,实际上只在 ./sources/cxx-stl/gnu-libstdc++/libs/ 版本的 C++ 库中找到它。这些库不包含在我制作的独立工具链中,而且我在设备上也找不到它们(设备正在运行 Honeycomb)。

NDK 中的文本明确指出,当我使用 stlport 时,支持整个 STL。这是只有冰淇淋三明治里才有的事吗?设备上和 NDK 中的 libstlport.so 或 libsupc++.so 没有任何签名,例如未找到的签名。

所以我的问题有两个部分:

  1. 构建过程/Android 设置中是否缺少某些内容?我是否可以进行不同的设置,以便程序无需 gnu-libstc++ 即可编译,或者至少因编译/链接错误而失败,而不是无法在设备上加载?
  2. 如果与 gnu-libstc++ 链接是唯一的方法,我该怎么做?我认为我可以管理到它的静态链接,但我宁愿不这样做。

如何将 gnu-libstdc++ 版本添加到我的

I'm trying to port a C++ utility program that I want to be run from the Android ADB shell.
For that, I'm using the Android NDK's make-standalone-toolchain.sh script, and compiling my program with it.
Unfortunately, when I try to run it, I get this error:

reloc_library[1315]: 16304 cannot locate '_ZNKSs5c_strEv'...
CANNOT LINK EXECUTABLE

After some research, I saw that this means that the c_str function doesn't exist in libstdc++.so in the NDK. I also couldn't find the symbol in stlport.so either, and actually only found it in the ./sources/cxx-stl/gnu-libstdc++/libs/ version of the C++ libraries. These libraries are not included in the standalone toolchain I made, and I also couldn't find them on the device (the device is running Honeycomb).

The text in the NDK clearly states that there's support for the entire STL when I use stlport. Is this something that is only true in Ice Cream Sandwich? The libstlport.so or in libsupc++.so on the device and in the NDK didn't have any signature like the one that wasn't found.

So my question has two parts:

  1. Is there something I'm missing in the build process/Android setup? Can I set up things differently so that the program will compile without needing the gnu-libstc++, or at least fail with a compilation/link error instead of failing to load on the device?
  2. If linking with gnu-libstc++ is the only way, how can I do that? I think I can manage statically link to it but I'd rather not.

How can I add the gnu-libstdc++ version to my

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彩虹直至黑白2025-01-09 12:02:59

如果其他人正在寻找解决方案,我最终使用 libgnustl_shared.so 上的 -l 开关添加了依赖项。您可以在 NDK 中找到它,

sources/cxx-stl/gnu-libstdc++/libs/<architecture>/

然后将这个 .so 与程序一起推送到设备,并制作一个脚本将当前目录添加到 LD_LIBRARY_PATH。这看起来与 NDK 在使用 make 脚本创建依赖于 gnustl 的程序时所做的事情类似。

If someone else is looking for a solution, I ended up adding a dependency using the -l switch on libgnustl_shared.so. You can find it inside the NDK at

sources/cxx-stl/gnu-libstdc++/libs/<architecture>/

I then pushed this .so together with the program to the device, and made a script that adds the current directory to LD_LIBRARY_PATH. It seems similar to what the NDK does when you use the make scripts to create a program that depends on gnustl.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文