Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
最新的C++;Android NDK的11个功能_Android_Gcc_C++11_Android Ndk_Clang - Fatal编程技术网

最新的C++;Android NDK的11个功能

最新的C++;Android NDK的11个功能,android,gcc,c++11,android-ndk,clang,Android,Gcc,C++11,Android Ndk,Clang,我试图在Android NDK上使用C++11线程功能,但不确定如何使用最新的编译器 我有Clang3.2,可以构建iOS应用程序。我想知道是否有一种方法可以用安卓NDK实现这一点 如果没有,那么我应该如何使用GCC4.8进行构建?中捆绑了Clang3.2编译器。使用它,您就可以开始了。首先,要决定使用哪个工具链,请编辑您的“application.mk”(不要与android.mk混淆)并插入gcc 4.8: NDK_TOOLCHAIN_VERSION := 4.8 或者如果你想要叮当声:

我试图在Android NDK上使用C++11线程功能,但不确定如何使用最新的编译器

我有Clang3.2,可以构建iOS应用程序。我想知道是否有一种方法可以用安卓NDK实现这一点


如果没有,那么我应该如何使用GCC4.8进行构建?

中捆绑了Clang3.2编译器。使用它,您就可以开始了。

首先,要决定使用哪个工具链,请编辑您的“application.mk”(不要与android.mk混淆)并插入gcc 4.8:

NDK_TOOLCHAIN_VERSION := 4.8
或者如果你想要叮当声:

NDK_TOOLCHAIN_VERSION := clang
但这与线程无关。这将仅定义要使用的工具链

关于线程,下面是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)
}
\include//value\u b==true)
{
printf(“VALUE=%i”,一些线程参数->值a);
}
//发出线程执行结束的信号
pthread_退出(0);
}
//---------------------------------
//这是创建和启动新线程的实际函数
void startThread()
{
//让我们把一些数据传递给新线程,你可以传递任何东西,甚至是大数据,
//为此,您只需要根据需要修改thread_data_参数
结构线程数据参数*一些线程参数;
一些线程参数=(线程数据参数*)malloc(sizeof(*一些线程参数));
一些线程参数->值a=12345;
一些线程参数->值b=true;
//创建并启动新线程
pthread_create(&native_thread,NULL,functionrunninginsepartethread,(void*)一些_thread_参数)
}

对于ndk版本,打开Application.mk并添加以下信息。其中(如果使用r8e):


注意:如果您使用的是NDK第9版,请使用4.8

NDK第10版拥有Clang 3.6工具链。使用它:

NDK_TOOLCHAIN_VERSION := clang3.6
或者使用最新可用的叮当工具链

NDK_TOOLCHAIN_VERSION := clang
(我正在处理NDK版本r9b) 要使C++11支持应用程序的所有源代码(以及包含的所有模块),请在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
否则,如果您希望仅在模块中支持C++11,请将这几行代码添加到您的Android.mk中,而不是使用APP_CPPFLAGS

LOCAL_CPPFLAGS += -std=c++11
请在此处阅读更多信息:

请注意,Android gcc支持现在已被弃用。您现在应该使用叮当声。请仔细阅读。您可以指定:

NDK_TOOLCHAIN_VERSION=clang

使用基于已安装NDK的最新版本。此外,在撰写本文时,最新的NDK(v12)只能通过Android Studio访问,而不能通过下载页面或独立SDK管理器访问。

请参见例如和@Michael,我需要使用clang 3.2或gcc 4.8构建,由于NDK修订版10d-GCC 4.8是所有32位ABISY的默认版本,您可以通过这种方式使用编译器,但是使用线程还需要做一些其他事情(我使用的是APP_STL:=gnustl_static),因为我得到了一个错误:命名空间“std”中没有名为“thread”的成员;你是说“fread”吗?@Kimi
$NDK/docs/STABLE-api.html
中的NDK文档说明如下:
注意,Android C库包括对pthread()的支持,因此不需要“LOCAL_LIBS:=-lpthread”。实时扩展也是如此(在典型的Linux发行版上为-lrt)
。你能将你面临的问题粘贴到问题中吗,这样可以更容易地追踪问题?奇怪的是,
clang3.6
正在为我使用3.8(目前最新的版本是5.1.1,通过预处理器
\ifdef
检查),比如
clang
。而
clang3.8
是一个错误。
NDK_TOOLCHAIN_VERSION=clang