9

Is it possible to compile C++14 source code for Android with ndk10d? I've tried both g++ and clang compilers but it seems that -std=c++14 -std=c++1y flags do not work.

If I use c++_static as my APP_STL, i get the following error:

User/someone/Software/Android/android-ndk-r10d/platforms/android-17/arch-arm/usr/include/locale.h:55:1: error: empty struct has size 0 in C, size 1 in C++

Edit: I am using Mac OSX 10.10.4 with Xcode 6.3.2 (able to compile C++14 for iOS).

Crossfire
  • 1,801
  • 3
  • 21
  • 37
  • I've been using C++14 with the NDK (R10c) for a while, so it does work. I'm using clang 3.4/3.5 to build, and gnustl_static as the STL (I couldn't build with c++_static; I don't remember the exact reason for that). I'm not sure if I used `-std=c++14` or `std=c++1y`, but I think it was `1y`. – Michael Jul 14 '15 at 18:46
  • I tried your settings but it still doesn't work, I'm using clang 3.6 (based on LLVM 3.6.0) – Crossfire Jul 15 '15 at 10:32

5 Answers5

6

I use android-ndk-r12b-windows-x86_64, compile success with -std=c++14

Android.mk

LOCAL_CPPFLAGS  = -Wall -std=c++14
KunMing Xie
  • 1,613
  • 17
  • 15
3

If someone needs an answer to this question, I have found it here.

It's called CrystaX and basically it is a modified version of the Android NDK that allows targeting C++14, Boost libraries and has a number of other features.

Crossfire
  • 1,801
  • 3
  • 21
  • 37
1

I'm using the following directives in my Application.mk. Switching to the clang toolchain via NDK_TOOLCHAIN_VERSION solved a bunch of problems.

APP_CPPFLAGS += -std=c++14
APP_STL := c++_static
NDK_TOOLCHAIN_VERSION := clang
nenchev
  • 1,998
  • 28
  • 16
0

If I use c++_static as my APP_STL, i get the following error:

User/someone/Software/Android/android-ndk-r10d/platforms/android-17/arch-arm/usr/include/locale.h:55:1: error: empty struct has size 0 in C, size 1 in C++

I'm getting the same when I'm using iostream. But this is only a warning (I'm using NDK 10e) and it builds just fine. The warning is "-Wextern-c-compat" which you could turn off just like any other warning.

Daniel Ryan
  • 6,976
  • 5
  • 45
  • 62
0

I create a android project with native cpp for c++17:

in the app/build.gradle file:

NDK: 21

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++17" # this answer key
            }
        }
    }
}

There is a demo for this, https://github.com/c0i/GameV4/commit/f9a3728f1aebc70d79dc9791cc9854ef5e41cae1

Thanks,

Jimmy KD
  • 633
  • 7
  • 14