Android Studio NDK Build ninja gcc / clang命令行选项

时间:2017-08-03 21:26:11

标签: android android-studio android-ndk ninja

在新的Android Studio NDK忍者构建系统(v 2.3+)中,转储实际gcc / clang命令行选项的最佳方法是什么?

目前,我故意在我的C文件中插入#error语句:

...
#include <gperf.h>

#error "Compiler, stop!"

#define LOGI(...) \
  ((void)__android_log_print(ANDROID_LOG_INFO, "hell-libs::", __VA_ARGS__))

这样我就可以获得以下命令行转储:

Build hello-libs arm64-v8a
[1/2] Building CXX object CMakeFiles/hello-libs.dir/hello-libs.cpp.o
FAILED: /Users/me/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  
--target=aarch64-none-linux-android --gcc-toolchain=/Users/me/android-ndk/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/me/android-ndk/platforms/android-21/arch-arm64  
-Dhello_libs_EXPORTS -I/Users/me/src/opensource/android-ndk/hello-libs/app/src/main/cpp/../../../../distribution/gmath/include -I/Users/me/src/opensource/android-ndk/hello-libs/app/src/main/cpp/../../../../distribution/gperf/include 
-isystem /Users/me/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /Users/me/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/include -isystem /Users/me/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security  -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security   -std=gnu++11 -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info  -fPIC -MD -MT CMakeFiles/hello-libs.dir/hello-libs.cpp.o -MF CMakeFiles/hello-libs.dir/hello-libs.cpp.o.d -o CMakeFiles/hello-libs.dir/hello-libs.cpp.o -c /Users/me/src/opensource/android-ndk/hello-libs/app/src/main/cpp/hello-libs.cpp
/Users/me/src/opensource/android-ndk/hello-libs/app/src/main/cpp/hello-libs.cpp:24:2: error: "Compiler, stop!"
#error "Compiler, stop!"
 ^
1 error generated.
ninja: build stopped: subcommand failed.
:app:externalNativeBuildDebug FAILED

1 个答案:

答案 0 :(得分:1)

根据此CMake PR:https://github.com/Kitware/CMake/commit/ce935ebe50926bde199d86fbde4a78974a4043f9

你应该能够通过-DCMAKE_VERBOSE_MAKEFILE = ON来获得Ninja -v,但我从来没有能够让它工作。我现在不知道为什么。

我通常获得标志的方法是打开由Android Studio / Gradle自动生成的文件android_gradle_build.json。该文件包含给定ABI的每个c / cpp文件的所有标志。