使用 Android NDK 和 std::vector 时修复 Eclipse 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7667017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:06:23  来源:igfitidea点击:

Fixing Eclipse errors when using Android NDK and std::vector

androideclipseandroid-ndk

提问by nkassis

I'm using eclipse to develop an android app that also uses the ndk. I vectors in my app and I've done the necessary stuff to get them by including

我正在使用 eclipse 开发一个也使用 ndk 的 android 应用程序。我在我的应用程序中使用矢量,并且我已经完成了必要的工作来获得它们,包括

APP_STL := stlport_static

APP_STL := stlport_static

In my Application.mk

在我的 Application.mk

Everything is working fine it compiles and runs but Eclipse keeps giving me errors when I use the vectors

一切正常,它可以编译和运行,但是当我使用向量时 Eclipse 不断给我错误

std::vector<int> blah

for example creates an error. If I delete the error and keep going it compiles and runs fine.

例如创建一个错误。如果我删除错误并继续运行,它会编译并运行良好。

I've added ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/include

我添加了 ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/include

In my project config under C++ General -> Paths and Symbols -> include

在我的项目配置下 C++ General -> Paths and Symbols -> include

It resolves #include <vector>fine (before I added the path above I had an error for this) but I still get errors using the vectors.

它解决得#include <vector>很好(在我添加上面的路径之前,我有一个错误)但我仍然使用向量出现错误。

How can I get eclipse to stop giving me errors for this?

我怎样才能让日食停止给我错误?

EDIT:

编辑:

example error: Symbol 'vector' could not be resolved

示例错误: Symbol 'vector' could not be resolved

EDIT 2:

编辑2:

I tried to add

我试着添加

using namespace std;

and then using vector blah and that causes a different error:

然后使用 vector blah 并导致不同的错误:

Invalid template arguments

无效的模板参数

回答by zooz

I've added ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/include

In my project config under C++ General -> Paths and Symbols -> include

我添加了 ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/include

在我的项目配置下 C++ General -> Paths and Symbols -> include

Yes, that's it. I've tried to add the same with the same result. However, if you add stl_port headers

对,就是那样。我试图添加相同的结果。但是,如果您添加 stl_port 标头

${NDKROOT}/sources/cxx-stl/stlport/stlport

It will do the trick. Of course it is not necessary to change

它会解决问题。当然没必要改

APP_STL := stlport_static

as it works only in eclipse indexes. It will be usefull until you are going to use something that exists in gnu-libstdc++ and doesn't exist stl-port.

因为它仅适用于 eclipse 索引。直到您要使用 gnu-libstdc++ 中存在但不存在 stl-port 的东西之前,它会很有用。

回答by sc7258

Blockquote

块引用

I am suing eclipse indigo rc2.

我正在起诉 eclipse indigo rc2。

I added following line in Android.mk

我在 Android.mk 中添加了以下行

LOCAL_C_INCLUDES += ${NDKROOT}/sources/cxx-stl/stlport/stlport

and Added following line in Application.mk

并在 Application.mk 中添加了以下行

APP_STL := stlport_static

then automatically my ndk stlport path added in

然后自动添加我的 ndk stlport 路径

Properties -> C++ General -> Paths and Symbols -> include

属性 -> C++ 通用 -> 路径和符号 -> 包含

good luck! ^^

祝你好运!^^

回答by user3387862

At first, we met the same problem with map and tried to add "Paths and Symbols" as suggested, however it still wouldn't work.

起初,我们遇到了与地图相同的问题,并尝试按照建议添加“路径和符号”,但仍然无法正常工作。

Later on, instead of

后来,而不是

#include <map>

we used

我们用了

#include <stl/_map.h>

The error went away and then we switched back to include <map>. Eclipse no longer complained that "Symbol could not be resolved".

错误消失了,然后我们切换回include <map>. Eclipse 不再抱怨“符号无法解析”。

It seems eclipse has a cache and somehow it can get messed up unless you specifically tell it the right place to find the symbols.

似乎 eclipse 有一个缓存,并且以某种方式它会变得一团糟,除非你特别告诉它找到符号的正确位置。

回答by valerycpp

I do not know at what stage it worked, but:

我不知道它在哪个阶段起作用,但是:

  1. Add to Application.mk APP_STL := gnustl_static

  2. Add include to Project properties->C/C++ General -> Paths and Symbols
    'NDK root path'/'your directory to android platform'/arch-arm/usr/include 'NDK root path'/sources/cxx-stl/gnu-libstdc++/4.9/include 'NDK root path'/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include/bits

  3. Turn off all warnings errors in Project properties->C++ General->Code Analisis.

  4. Project properties->C++ Build-> Builder Settings -> Uncheck use default build command. Build command set empty.
  5. Next configure NDK Builder: Project properties-> Builders-> New-> Program and fill Name (your name build conf), Location (path to NDK root directory), Working directory (path to project dir). -> Refresh and check specific resources (your libs folder in project). -> Build Options check Specify working set of relevant resources and change 'jni' folder with your source.
  1. 添加到 Application.mk APP_STL := gnustl_static

  2. 将包含添加到项目属性->C/C++ General -> Paths and Symbols
    'NDK root path'/'your directory to android platform'/arch-arm/usr/include 'NDK root path'/sources/cxx-stl/gnu-libstdc++/4.9/include 'NDK root path'/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include/bits

  3. 关闭项目属性->C++ 通用->代码分析中的所有警告错误。

  4. 项目属性->C++ 构建-> 构建器设置-> 取消选中使用默认构建命令。构建命令集为空。
  5. 接下来配置NDK Builder:Project properties->Builders->New->Program并填写Name(你的名字build conf),Location(NDK根目录的路径),Working directory(项目目录的路径)。-> 刷新并检查特定资源(项目中的 libs 文件夹)。-> 构建选项检查指定相关资源的工作集并使用您的源更改“jni”文件夹。

worked in Ubuntu 15.04. Eclipse 3.8.1. Android NDK r10e.

在 Ubuntu 15.04 中工作。日食 3.8.1。安卓 NDK r10e。