将 STL 与 Android NDK 结合使用时的 Eclipse 索引器错误

发布于 2025-01-07 18:55:55 字数 864 浏览 2 评论 0原文

我在 Ubuntu 上使用 Android NDK r7 和 eclipse Indigo。 我将我的 java 项目设置为使用 C++ 性质。 我在 C++ 端使用 STL,所以我添加了

APP_STL := gnustl_static

在Application.mk 文件中。

ndk-build 成功编译我的代码并创建共享对象。

然而 Eclipse 索引器抱怨缺少 STL 符号。例如

“无法解析方法‘push_back’”“符号‘向量’无法解析 已解决”

仅当在编辑器中打开 C++ 文件时 发生这种情况。 最终 eclipse 不会创建我的 apk。 我添加了 ndk 附带的 gnu STL 标头的路径(属性 => C/C++ 常规 => Code Analasys => 路径和符号):

android-ndk-r7/sources/cxx-stl/gnu-libstdc++/include
android-ndk-r7/sources/cxx-stl/gnu-libstdc++/include/bits

当前的解决方法是关闭打开的 C++ 文件以使 eclipse 满意。

有趣的是,Eclipse 索引器可以很好地处理以下位置的标头:

android-ndk-r7/platforms/android-14/arch-arm/usr/include

有什么我忘记在 eclipse 中设置的吗?

I'm using the Android NDK r7 with eclipse Indigo on Ubuntu.
I set up my java project to use the C++ nature.
I'm using STL on C++ side so I added

APP_STL := gnustl_static

in the Application.mk file.

ndk-build succeed compiling my code and creating a shared object.

However eclipse indexer complains about missing STL symbols. For example

"Method 'push_back' could not be resolved" "Symbol 'vector' could not
be resolved"

This happens only when C++ files are open in the editor.
Ultimately eclipse won't create my apk.
I added path to the gnu STL headers shiped with the ndk (Properties => C/C++ General => Code Analasys => Path & symbols) :

android-ndk-r7/sources/cxx-stl/gnu-libstdc++/include
android-ndk-r7/sources/cxx-stl/gnu-libstdc++/include/bits

Current workaround is to close opened C++ files to make eclipse happy.

Interestingly eclipse indexer's working fine with headers found in

android-ndk-r7/platforms/android-14/arch-arm/usr/include

Is there something I forgot to set up in eclipse ?

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

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

发布评论

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

评论(2

彩虹直至黑白 2025-01-14 18:55:56

您必须将 STL 的路径添加到项目设置中,以便 Eclipse 也对其进行索引。项目 -> 属性 -> C/C++ 常规 -> 包含。这是我添加的内容:

<path_to_NDK>/sources/cxx-stl/gnu-libstdc++/include
<path_to_NDK>/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/include
<path_to_NDK>/platforms/android-9/arch-arm/usr/include

You have to add path to STL to project settings so that Eclipse indexes it as well. Project->Properties->C/C++ General->Includes. Here's what I have added:

<path_to_NDK>/sources/cxx-stl/gnu-libstdc++/include
<path_to_NDK>/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/include
<path_to_NDK>/platforms/android-9/arch-arm/usr/include
丶视觉 2025-01-14 18:55:56

有些人已经能够通过将 __GXX_EXPERIMENTAL_CXX0X__ 添加到 Eclipse 来解决此问题,如“智能指针不适用于 Android NDK r8"。但这在某些版本的 Eclipse 中不起作用,例如我的版本(Eclipse Juno v4.2)。

因此,作为一种解决方法,我转到 Eclipse Preferences -> C/C++->代码分析,然后我将一些问题的严重性从错误更改为警告,因为无论如何我都使用 NDK 编译我的代码,所以这些只会影响索引器。我更改了“符号未解析”并修复了我的错误,但您可能还想更改其他一些错误。起初它没有为我修复错误,直到我关闭并关闭它。重新打开 C++ 文件。右键单击您的项目并选择“索引 -> 重建”也可能有助于刷新它。

现在,Eclipse 将这些行突出显示为警告,并允许我继续构建和构建。跑步&调试我的 NDK 应用程序。

Some people have been able to fix this problem by adding __GXX_EXPERIMENTAL_CXX0X__ to Eclipse as mentioned in "smart pointers not working with Android NDK r8". But this doesn't work in some versions of Eclipse such as my one (Eclipse Juno v4.2).

So as a work-around hack, I went to Eclipse Preferences -> C/C++ -> Code Analysis, then I changed the severity of some problems from Error to Warning, since I am using NDK to compile my code anyway so these only effect the Indexer. I changed "Symbol is not resolved" and it fixed my errors, but you might also want to change a few others. At first it didn't fix the errors for me until I closed & re-opened the C++ file. Right-clicking on your project and selecting "Index -> Rebuild" might also help refresh it.

Now Eclipse highlights those lines as warnings and allows me to continue building & running & debugging my NDK app.

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