Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

c++ - smart pointers not working with Android NDK r8

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 <memory> in my cpp file. Now Eclipse tells me Unresolved inclusion: <memory>, but I get the same thing for <vector> and <string> 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...