Eclipse-CDT 无法在 NDK 项目中找到 stdlib 符号

发布于 2024-12-23 11:31:10 字数 1311 浏览 1 评论 0原文

我正在尝试使用 NDK 和 C++ 编写一个简单的 Android 应用程序。具体来说,我想使用最新版本 NDK (r7) 中包含的 gnustdc++。 JNI 库已经像 C 一样编译和工作得很好,但现在我试图引入 C++,我遇到了一些问题。

我已将 ${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/include/ 添加到我的项目的包含路径中,并且 #includes 内联已解析。但是,尝试实际使用任何 STL 类(例如矢量)会导致无法解析符号“矢量”

导入的所有标准 C 符号都可以正常工作,直到我尝试将 #include 替换为 为止。。然后它会失败,并显示无法解析函数'malloc'等等。

奇怪的是,添加 stlport 标头(在 ${NDK_ROOT}/sources/cxx-stl/stlport/stlport 中)解决了我的所有问题。然而,我是在 GNU C++ 中链接,而不是 STLPort,所以这充其量是一个不方便且不正确的“解决方案”。这些标头可以工作,但其他标头却不能,这似乎很奇怪。 Eclipse 是否无法索引或解析 GNU C++ 标头?

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := libfoobar-jni
LOCAL_SRC_FILES := foobar.cpp
LOCAL_LDLIBS := -llog -lGLESv2

LOCAL_C_INCLUDES := sources/cxx-stl/gnu-libstdc++/include/
LOCAL_CFLAGS := -g -std=c99

include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL := gnustl_shared

编辑:我根据以下内容设置了我的项目:

http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/

I am trying to write a simple Android application using the NDK and C++. Specifically, I'd like to use the gnustdc++ included with the newest version of the NDK (r7). The JNI library has compiled and worked perfectly fine as C, but now that I'm trying to introduce C++, I've run into some issues.

I have added ${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/include/ to my project's include paths, and the #includes inline are resolved. However, attempting to actually use any STL class (such as vector) results in Symbol 'vector' could not be resolved.

All of the standard C symbols imported from <stdlib.h> and such work as well, until I try to replace the #include with <cstdlib>. Then it fails with Function 'malloc' could not be resolved and so forth.

Oddly enough, adding the stlport headers (in ${NDK_ROOT}/sources/cxx-stl/stlport/stlport) fixes all of my issues. However I am linking in GNU C++, not STLPort, so this is an inconvenient and improper "solution" at best. It seems odd that these headers would work but the others would not. Is Eclipse failing to index or resolve the GNU C++ headers?

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := libfoobar-jni
LOCAL_SRC_FILES := foobar.cpp
LOCAL_LDLIBS := -llog -lGLESv2

LOCAL_C_INCLUDES := sources/cxx-stl/gnu-libstdc++/include/
LOCAL_CFLAGS := -g -std=c99

include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL := gnustl_shared

Edit: I set up my project based on:

http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/

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

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

发布评论

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

评论(3

空名 2024-12-30 11:31:10

阅读此内容,它有解决方案:

http://comments.gmane.org /gmane.comp.handhelds.android.ndk/14371

如果有一天链接失效的话,总结如下:

这是 gnustl_shared 模块声明中的一个错误。抱歉,该问题将在下一个版本中修复。
同时,您可以手动更改 $NDK/sources/cxx-stl/gnu-libstdc++/Android.mk 并将以下行替换

LOCAL_EXPORT_LDLIBS := $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libsupc++.a

为:

LOCAL_EXPORT_LDLIBS := $(call host-path,$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libsupc++.a)

Read this, it has the solution:

http://comments.gmane.org/gmane.comp.handhelds.android.ndk/14371

The summary, in case the link dies some day is this:

It's a bug in the gnustl_shared module declaration. Sorry about that, it will be fixed in the next release.
In the meantime, you can manually change $NDK/sources/cxx-stl/gnu-libstdc++/Android.mk and replace the line that says:

LOCAL_EXPORT_LDLIBS := $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libsupc++.a

with:

LOCAL_EXPORT_LDLIBS := $(call host-path,$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libsupc++.a)
御弟哥哥 2024-12-30 11:31:10

我知道这不是一个完美的解决方案,但至少它可以让您通过 Eclipse 单击“运行”或“调试”:

  • 右键单击您的 Android C++ 项目并选择“属性”。
  • 在“C/C++ 常规”下,单击“代码分析”
  • 切换到“使用项目设置”
  • 将由于使用向量类而收到的任何错误切换为“警告”。

对我来说,到目前为止我需要切换的错误是:

  • “符号未解析”
  • “未找到成员声明”
  • “模板参数无效”
  • “参数无效”
  • “方法无法解析”

就像我说的,它并不完美,您可能会因此错过真正的错误,但您仍然能够通常选择“转到声明”和一些语法检查功能,以及启动程序的能力。无论如何,ndk-build 步骤都会捕获任何真正的错误,因此这实际上并不是一个巨大的损失。
老实说,我不确定这个问题的根源。这很可能是 Eclipse 的错误。

偏离主题但相关:您还可以通过 eclipse 使用 ndk-gdb。该教程位于链接到OP的博客上,但是

祝你好运!


编辑(后续):

我已经找到了解决这个问题的方法,至少在我的盒子上是这样。 OP 说,包括 STLPORT 标头对他有用。起初,这不适合我。我必须销毁我的 Eclipse 项目并重新开始(由于某种原因,它不允许我删除一些包含定义)。添加 STLPORT 修复了一些问题,但在 ndk r7b 中,我仍然遇到奇怪的错误(例如,即使在包含 stddef 后也未定义 NULL)。我最终也必须包含 x86 标头。这些应该在很大程度上与手臂重叠,但是,将手臂放在包含顺序中的“顶部”很有用。

因此,如果您遇到了与我相同的问题,请将


$NDK_DIR/platforms/android-14/arch-x86/usr/include


添加到您的 eclipse 包含列表中。

I know it's not a perfect solution, but at least it'll let you click "run" or "debug" through Eclipse:

  • Right click on your Android C++ project and select Properties.
  • Under C/C++ General, click "Code Analysis"
  • Switch to "Use project settings"
  • Switch any errors you're receiving due to using the vector class to be "warnings".

For me, the errors I've needed to switch so far are:

  • "Symbol is not resolved"
  • "Member declaration not found"
  • "Invalid template argument"
  • "Invalid arguments"
  • "Method cannot be resolved"

Like I said, it's not perfect and you might miss real errors due to this, but you still get the ability to usually select "Go To Declaration" and some syntax checking abilities, as well as the ability to launch your program. The ndk-build step will catch any real errors anyway, so it's really not a huge loss.
Honestly, I'm not sure of the source of this issue. It's likely got to be an Eclipse bug.

Off topic but relevant: you can also use the ndk-gdb through eclipse. The tutorial is on the blog linked to the OP, but here's a direct link anyway.

Best of luck!


Edit (followup):

I've since figured out a way to get around this problem, at least on my box. The OP said that including the STLPORT headers worked for him. It didn't for me, at first. I had to destroy my Eclipse project and start fresh (for some reason, it wouldn't let me remove some include definitions). Adding STLPORT fixed some issues, but in ndk r7b, I was still getting weird errors (e.g. NULL was not defined even after including stddef). I ended up having to include the x86 headers too. These should largely overlap with the arm ones, however, it's useful to have the arm ones 'on top' in the include order.

So, if you've been running into the same issue as I was, add


$NDK_DIR/platforms/android-14/arch-x86/usr/include


to your list of eclipse includes as well.

一场信仰旅途 2024-12-30 11:31:10

由于我最喜欢的 Windows shell cygwin 中的路径格式不同,并且它使用伪 unix 样式路径而不是 Windows,因此我在 Windows 上出现了此问题。如果您遇到此问题,并且您的路径中存在 cygwin,则 Eclipse 可能正在使用它。将“属性”>“C 常规”>“路径和符号”中的路径更改为 cygwin 样式而不是 Windows 样式(/cygwin/c/Android...而不是 C:\Android...)...无论如何,这对我有用。

I had this issue come up on windows due to the different path formats in cygwin, my prefered windows shell, and which uses pseudo unix style paths rather than windows. If you are having this problem, and you have cygwin floating around in your path, eclipse could be using it. Change the paths in Properties>C General>Paths and Symbols to be cygwin style rather than windows style (/cygwin/c/Android.... rather than C:\Android...) ... anyway, this worked for me.

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