पहले, जो toolchain उपयोग करते हैं, अपने "application.mk" संपादित (android.mk साथ भ्रमित नहीं है) और जीसीसी 4.8 के लिए सम्मिलित करने के लिए तय करने के लिए:
NDK_TOOLCHAIN_VERSION := 4.8
या यदि आप बजना हैं:
NDK_TOOLCHAIN_VERSION := clang
लेकिन इसका धागे से कोई लेना देना नहीं है। यह केवल परिभाषित करेगा कि कौन सा टूलचेन उपयोग करना है।
#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)
}
उदा। देखें http://stackoverflow.com/questions/15269496/how-to-compile-c11-code-with-android-ndk-and-eclipse और http: // stackoverflow।कॉम/प्रश्न/1401465 9/एंड्रॉइड-एनडीके-त्रुटि-होना-सक्षम-साथ-the-std-c11-or-std-gnu11-compiler – Michael
@ माइकल, मुझे क्लैंग 3.2 या जीसीसी 4.8 के साथ निर्माण करने की आवश्यकता है, या हो सुनिश्चित करें कि यह संभव नहीं है और pthreads का उपयोग करें। – Kimi
चूंकि एनडीके संशोधन 10 डी - जीसीसी 4.8 सभी 32-बिट एबीआई –