Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling C++11 sources for Android NDK

I'm trying to compile some C++11 sources with Android NDK on Windows, but without much luck. Please note, that I've read some other questions about compiling C++11, but they didn't help much unfortunately.

I've downloaded the ADT Bundle and latest NDK (android-ndk-r9b-windows-x86.zip).

These are my configuration files:

Application.mk

APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION = 4.8
LOCAL_CPP_FEATURES += exceptions
LOCAL_CFLAGS += -std=c++11

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := procalc-core

LOCAL_SRC_FILES := pcc_arithmetics.cpp \
pcc_arithmetics_tools.cpp \
pcc_common.cpp \
pcc_core.cpp \
pcc_dms_tokenizer.cpp \
pcc_dynamic_numerics.cpp \
pcc_exceptions.cpp \
pcc_expressiontree.cpp \
pcc_expression_containers.cpp \
pcc_messages.cpp \
pcc_numerics.cpp \
pcc_resolvers.cpp \
pcc_syntaxtree.cpp \
pcc_tokenizer.cpp \
sm_Bignum.cpp \
sm_Math2D.cpp \
sm_MathNumerics.cpp \
ss_Streams.cpp

include $(BUILD_SHARED_LIBRARY)

Build command

cd %AndroidProjects%ProCalc\jni\
D:\Android\ndk\ndk-build

pause

The error
That's actually one of the errors, but it's clearly not recognizing new C++11 keywords like auto or nullptr.

D:/(path)/jni/pcc_arithmetics.cpp: In static member function 'static 
ProCalcCore::BaseNumeric* (* ProCalcCore::Arithmetics::GetFunctionMethod(std::string))
(const std::vector<const ProCalcCore::BaseNumeric*>&)': 
D:/(path)/jni/pcc_arithmetics.cpp:4077:11: error: 'nullptr' was not declared in 
this scope

return nullptr;
       ^

What am I doing wrong?

like image 523
Spook Avatar asked Dec 19 '22 21:12

Spook


1 Answers

LOCAL_CPP_FEATURES += exceptions
LOCAL_CFLAGS += -std=c++11

Should go into Android.mk file. Alternatively, you could put

APP_CFLAGS += -std=c++11

into Application.mk. You can also use APP_CPPFLAGS instead, so that the C sources in your project (if you choose to add them) could compile (the C compiler will not like -std=c++11).

like image 139
Alex Cohn Avatar answered Jan 04 '23 06:01

Alex Cohn