smart pointers not working with Android NDK r8

匿名 (未验证) 提交于 2019-12-03 01:06:02

问题:

I can't figure out how to use shared pointers within my Android project. I'm using the latest Eclipse ADT on Mac OS X with the Android NDK r8d.

Here is what is in my Android.mk file:

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_CPPFLAGS  := -std=c++11 LOCAL_MODULE    := native LOCAL_SRC_FILES := native.cpp include $(BUILD_SHARED_LIBRARY)

Here is what is in my Application.mk file:

NDK_TOOLCHAIN_VERSION=4.7 APP_STL := stlport_shared

I've tried the default GCC 4.6, the experimental 4.7, and the clang3.1 toolchains.
I've tried linking to stlport_shared and gnustl_shared c++ runtime libraries.
I've tried the FLAGS -std=c++11, -std=c++0x, and the -std=gnu++11.

I'm able to use lambdas and auto of the c++11 standard, so the C++11 flag appears to be working. However anytime I try and use a shared_ptr, weak_ptr, or unique_ptr, I get the error 'suchandsuch_ptr' is not a member of 'std'

I have the #include in my cpp file. Now Eclipse tells me Unresolved inclusion: , but I get the same thing for and and those appear to compile and work just fine.

Are smart pointers not implemented in the toolchains included in the Android NDK?
If not, why not? Since GCC and clang have had support for smart pointers for quite some time, this would mean that I am either missing something, or the Android devs have disabled them for some reason.
Any clues?

回答1:

Be sure that the standard library include path (like /android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include) is in the target settings.

To get the IDE to recognize C++11 classes in the GNU standard library, add __GXX_EXPERIMENTAL_CXX0X__ as a predefined macro to the indexer. (The name is a bit of anachronism since C++11 is standardized and the support is no longer experimental, but as yet that's what it's called.) Also, be sure the indexer is set to reflect the correct build target.



回答2:

these settings did it for me:

Application.mk:

NDK_TOOLCHAIN_VERSION=4.7 APP_STL := gnustl_static

Android.mk:

LOCAL_CFLAGS :=-D__GXX_EXPERIMENTAL_CXX0X__  <--important LOCAL_CPPFLAGS  := -std=c++11

Eclipse Settings: C/C++ General\Path and Symbols should contain:

C:\android\ndk\sources\cxx-stl\gnu-libstdc++\4.7\include C:\android\ndk\sources\cxx-stl\gnu-libstdc++\4.7\libs\armeabi\include


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!