android gcc c++11 android-ndk clang

Las últimas características de C++ 11 con Android NDK



gcc c++11 (6)

(Me dirijo a la versión r9b del NDK) Para habilitar el soporte de C ++ 11 para todo el código fuente de la aplicación (y por lo tanto, cualquier módulo incluido) realice el siguiente cambio en el Application.mk:

# use this to select gcc instead of clang NDK_TOOLCHAIN_VERSION := 4.8 # OR use this to select the latest clang version: NDK_TOOLCHAIN_VERSION := clang # then enable c++11 extentions in source code APP_CPPFLAGS += -std=c++11 # or use APP_CPPFLAGS := -std=gnu++11

De lo contrario, si desea tener soporte para C ++ 11 solo en su módulo, agregue estas líneas en su Android.mk en lugar de usar APP_CPPFLAGS

LOCAL_CPPFLAGS += -std=c++11

Lea más aquí: http://adec.altervista.org/blog/ndk_c11_support/

Estoy tratando de usar los recursos de subprocesos de C ++ 11 con el NDK de Android, pero no estoy seguro de cómo hacer que utilicen los últimos compiladores.

Tengo Clang 3.2 y puedo construir aplicaciones de iOS. Me pregunto si hay alguna forma de hacerlo con Android NDK.

Si no es así, ¿cómo debo construir con gcc 4.8?


La revisión 10 de NDK tiene la cadena de herramientas Clang 3.6. Úsalo:

NDK_TOOLCHAIN_VERSION := clang3.6

o usa la última herramienta disponible de Clang

NDK_TOOLCHAIN_VERSION := clang


Para las compilaciones ndk, abra Application.mk y agregue la siguiente información. en ella (si usa r8e):

NDK_TOOLCHAIN_VERSION=4.7

Nota: Utilice 4.8 en caso de que esté utilizando la versión 9 de NDK.


Primero, para decidir qué cadena de herramientas usar, edite su "application.mk" (no confunda con android.mk) e inserte para gcc 4.8:

NDK_TOOLCHAIN_VERSION := 4.8

o si quieres clang:

NDK_TOOLCHAIN_VERSION := clang

Pero esto no tiene nada que ver con hilos. Esto solo definirá qué cadena de herramientas usar.

Ahora acerca de los hilos, aquí hay un ejemplo simple para Android NDK:

#include <pthread.h> // <--- IMPORTANT // This will be used to pass some data to the new thread, modify as required struct thread_data_arguments { int value_a bool value_b; }; //--------------------------------- // This function will be executed in the new thread, do not forget to put * at the start of the function name declaration void *functionRunningInSeparateThread(void *arguments) { struct thread_data_arguments *some_thread_arguments = (struct thread_data_arguments*)arguments; if (some_thread_arguments->value_b == true) { printf("VALUE= %i", some_thread_arguments->value_a); } // Signal the end of the thread execution pthread_exit(0); } //--------------------------------- // This is the actual function creating and starting the new thread void startThread() { // Lets pass some data to the new thread, you can pass anything even large data, // for that you only need to modify thread_data_arguments as required struct thread_data_arguments *some_thread_arguments; some_thread_arguments = (thread_data_arguments*)malloc(sizeof(*some_thread_arguments)); some_thread_arguments->value_a = 12345; some_thread_arguments->value_b = true; // Create and start the new thread pthread_create(&native_thread, NULL, functionRunningInSeparateThread, (void*)some_thread_arguments) }


Tenga en cuenta que la compatibilidad con Android GCC ahora está en desuso . Ahora deberías estar usando el clang. Por favor, lea las notas de la versión 11 . Puede especificar:

NDK_TOOLCHAIN_VERSION=clang

Para usar la última versión basada en tu NDK instalado. Además, al momento de escribir esto, al NDK más reciente (v12) solo se puede acceder a través de Android Studio, y no a través de la página de Descargas o el Administrador de SDK independiente.