Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

c++ - How do I tell Android Studio to use GCC 4.9 with CMake?

I'm using NDK r12 with Android Studio 2.2. I need CMake to use GCC 4.9 instead of Clang to build our code base, however even if I provide the following it still uses clang:

android {
    compileSdkVersion 17
    buildToolsVersion "25.0.0"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 17

        externalNativeBuild {
            cmake {
                arguments '-DBUILD_TESTING=OFF -DANDROID_TOOLCHAIN=gcc-4.9'
                cppFlags "-std=c++14 -fexceptions -frtti"
            }
        }
    }
}

I've tried -DANDROID_TOOLCHAIN=gcc as well but this doesn't work either. How can I get CMake to use GCC ARM toolchain?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Split your arguments string into one string per argument:

arguments '-DBUILD_TESTING=OFF','-DANDROID_TOOLCHAIN=gcc'

I don't know if it's possible to explicitly specify version 4.9 of GCC ("gcc-4.9" didn't work). However, that's redundant anyway since GCC 4.8 was removed in NDK r11, so GCC 4.9 is now the only version of GCC included in the NDK, and ANDROID_TOOLCHAIN=gcc therefore implicitly means GCC 4.9.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...