2

I'm building some C++ project for android to use it on unity plugin. I succeed to compile for iOS, but I get the following error for android:

~/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/stl_algo.h:3789:14: error: invalid use of 'auto'

~/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/future:114:11: error: declaration of 'class std::future<void>'
 class future;

I'm using android-ndk-r10e and this CMakeLists.txt code:

cmake_minimum_required(VERSION 2.8)
project(PluginAndroid)

# Android configuration
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 19) # API level
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
set(CMAKE ANDROID_STL_TYPE stlport_static)
set(CMAKE_ANDROID_TOOLCHAIN_NAME arm-linux-androideabi-4.8)
set(CMAKE_CXX_STANDARD 11)


include_directories ("${PROJECT_SOURCE_DIR}/3rdParty/common/")
....

file(GLOB source_files
    "*.h"
    "*.cpp"
)

add_library(PluginAndroid STATIC ${source_files})

Any clue to fix this issue?

rocambille
  • 15,398
  • 12
  • 50
  • 68
Jinho Yoo
  • 1,352
  • 5
  • 17
  • 28

1 Answers1

1

As pointed in the comments CMAKE_CXX_STANDARD is available since version 3.1 of CMake (if you're using firefox, see my add-on here to see the version since which a cmake feature is available), so you should change your minimal required version.

Moreover, you should mark the standard as required using CMAKE_CXX_STANDARD_REQUIRED.

Finally, you should use target_compile_features to ensure your compiler supports auto keyword (gcc 4.9 doesn't provide a full support for C++11 features).

Here is a modified version of your CMake file:

cmake_minimum_required(VERSION 3.1)
project(PluginAndroid)

# Android configuration
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 19) # API level
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
set(CMAKE ANDROID_STL_TYPE stlport_static)
set(CMAKE_ANDROID_TOOLCHAIN_NAME arm-linux-androideabi-4.8)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories ("${PROJECT_SOURCE_DIR}/3rdParty/common/")
....

file(GLOB source_files
    "*.h"
    "*.cpp"
)

add_library(PluginAndroid STATIC ${source_files})
target_compile_features(PluginAndroid PUBLIC cxx_auto_type)

Unrelated, but note that using GLOB to collect source files is not recommended in documentation:

We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate.

rocambille
  • 15,398
  • 12
  • 50
  • 68