如何在cmake Android Studio中添加cflag?

时间:2017-05-31 20:30:00

标签: android-ndk cmake

如何在Cmake配置文件中添加-D_FILE_OFFSET_BITS = 64。我试图在build.gradle中添加cflag,但它不起作用。

    externalNativeBuild {
        cmake {
            cppFlags ""
            cFlags "-D_FILE_OFFSET_BITS=64"
            arguments "-DANDROID_TOOLCHAIN=gcc"
        }
    }

1 个答案:

答案 0 :(得分:3)

在CMakeLists.txt文件中,我执行以下操作:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__ANDROID__ -DANDROID -DCUSTOM_FLAG")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGL_GLEXT_PROTOTYPES=1 -DIOAPI_NO_64 -DUSE_FILE32API ")

但是,您也可以使用gradle,但externalNativeBuild需要位于defaultConfigreleasedebug(构建风格)下cmake options传递旗帜。

例如:



    android {
        compileSdkVersion 25
        buildToolsVersion '25.0.3'
        defaultConfig {
            applicationId "..."
 
            externalNativeBuild {
                cmake {
                    // here, arguments, cppFlags, cFlags, ..  all work
                    arguments '-DANDROID_PLATFORM=android-15',
                            '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static',
                            '-DANDROID_CPP_FEATURES=rtti exceptions'
                }
            }
        }
        externalNativeBuild {
            cmake {
                // only 'path' variable is valid here
                path '../../gameSource/CMakeLists.txt'
            }
        }
        buildTypes {
            release {
               // .. release flavor
            }
            debug {
                //... debug flavor
            }
        }
    }