Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 372
BigMacAttack Avatar asked Jan 25 '13 23:01

BigMacAttack


2 Answers

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.

like image 116
Potatoswatter Avatar answered Oct 10 '22 09:10

Potatoswatter


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
like image 29
pulp Avatar answered Oct 10 '22 08:10

pulp