2013-06-17 10 views
16

Sto cercando di utilizzare C++ 11 impianti di filettatura con Android NDK, ma non è sicuro come fare utilizzare gli ultimi compilatori.Ultimi C++ 11 funzioni con Android NDK

devo Clang 3.2 e può costruire applicazioni iOS. Mi chiedo se c'è un modo per farlo con Android NDK?

Se no, allora come devo costruire con gcc 4.8?

+0

Vedere ad es. http://stackoverflow.com/questions/15269496/how-to-compile-c11-code-with-android-ndk-and-eclipse e http: // StackOverflow.it/questions/14014659/android-ndk-error-deve-essere-abilitato-con-lo-std-c11-o-std-gnu11-compiler – Michael

+0

@ Michael, ho bisogno di compilare con clang 3.2 o gcc 4.8, o essere certo che non è possibile e usare pthreads. – Kimi

+0

Dalla revisione 10d NDK - GCC 4.8 è l'impostazione predefinita per tutti gli ABI a 32 bit –

risposta

12

NDK revisione 10 ha la Clang 3.6 toolchain. Usalo:

NDK_TOOLCHAIN_VERSION := clang3.6 

o utilizzare l'ultima disponibile Clang toolchain

NDK_TOOLCHAIN_VERSION := clang 
+0

Stranamente, 'clang3.6' sta usando 3.8 per me (attualmente il più recente su 5.1.1, controllato tramite il preprocessore' # ifdef'), come 'clang'. E 'clang3.8' è un errore. –

2

NDK revision 8e ha la Clang 3.2 del compilatore in bundle in esso. Usalo e sei a posto.

+0

È possibile utilizzare un compilatore in questo modo, ma è necessario fare altro per utilizzare il threading (sto usando APP_STL: = gnustl_static) poiché sono ottenendo un errore di errore: nessun membro chiamato 'thread' nello spazio dei nomi 'std'; volevi dire "fread"? – Kimi

+0

@Kimi la documentazione NDK in '$ NDK/docs/STABLE-APIS.html' dice quanto segue:' Si noti che la libreria C di Android include il supporto per pthread (), quindi "LOCAL_LIBS: = -lpthread" non è necessario. Lo stesso vale per le estensioni in tempo reale (-lrt sulle tipiche distribuzioni Linux) '. Potresti incollare i problemi che affronti nella domanda, in quanto ciò renderà più facile tracciare il problema? – Samveen

1

In primo luogo, decidere quale toolchain da utilizzare, modificare il "application.mk" (da non confondere con android.mk) e inserire per gcc 4.8:

NDK_TOOLCHAIN_VERSION := 4.8 

o se si desidera clang:

NDK_TOOLCHAIN_VERSION := clang 

Ma questo non ha nulla a che fare con i thread. Questo definirà solo quale toolchain usare.

Ora circa le discussioni, ecco un semplice esempio per 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) 
} 
1

Per NDK costruisce, aperto Application.mk e aggiungere seguenti informazioni. in esso (se si utilizza r8e):

NDK_TOOLCHAIN_VERSION=4.7 

Nota: Si prega di utilizzare 4.8 nel caso in cui si utilizza NDK revisione 9.

18

(sto affrontando la versione r9b NDK) Per abilitare il supporto C++ 11 per tutto il codice sorgente dell'applicazione (e così tutti i moduli inclusi) apportare la seguente modifica nella 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 

in caso contrario, se si desidera avere C++ 11 supportano solo nel modulo, aggiungere queste linee nel vostro Androi d.mk invece di utilizzo APP_CPPFLAGS

LOCAL_CPPFLAGS += -std=c++11 

Read more here: http://adec.altervista.org/blog/ndk_c11_support/

0

noti che Android il supporto gcc è ormai deprecato. Ora dovresti usare clang. Si prega di leggere il version 11 release notes. È possibile specificare:

NDK_TOOLCHAIN_VERSION=clang 

Per utilizzare la versione più recente in base all'NDK installato. Inoltre --- al momento della stesura --- l'ultimo NDK (v12) è accessibile solo tramite Android Studio e non attraverso la pagina Download o il Gestore dell'SDK standalone.