-dM
命令(至少
clang
和
gcc
似乎)。在我的例子中,我想看看哪些预处理器宏是由Android构建系统设置的。这有点复杂,因为Android NDK有许多编译器,所有编译器的构建都略有不同。因此,我创建了以下python 3脚本,以将所有宏包含保存到文件中:
import os, sys
# Define the toolchain root
root = "C:\\Android\\android-sdk\\ndk-bundle\\toolchains\\"
# Define the directory where you want all of the macro definitions to go
output = "output\\"
os.makedirs(output, exist_ok=True)
# Get a list of all of the files
files = [ ( os.path.join(dp, f), f ) for dp, dn, fn in os.walk(os.path.expanduser(root)) for f in fn ]
# We only want executables
files = [ file for file in files if file[1].endswith("exe") ]
# Now, let's limit that to executables that contain one of the following keys
keys = [ "gcc", "g++", "clang", "c++", "cpp" ]
files = [ file for file in files if any(key in file[1] for key in keys) ]
# and that exclude the following keys
keys = [ "-ar", "-nm", "-ranlib", "filt", "-format", "-tidy" ]
files = [ file for file in files if all(key not in file[1] for key in keys) ]
# Now, for each of these files, we want to see what preprocessor macros are being set.
call = " -dM -E - < NUL > "
for file in files:
command = file[0] + call + output + file[1].replace(".exe", ".txt" ).replace(root,"")
print(command)
os.system( command )
python introspect.py
这个脚本所做的是查找所有
*.exe
文件(对于linux系统更改此选项)
root
目录(在我的系统上
C:\\Android\\android-sdk\\ndk-bundle\\toolchains\\
)它应该在某个地方包含编译器。具体来说,该脚本将查找具有其中一个术语的所有可执行文件
[ "gcc", "g++", "clang", "c++", "cpp" ]
在名称中,不包括具有
[ "-ar", "-nm", "-ranlib", "filt", "-format", "-tidy" ]
以我的名义。最后,找到的每个可执行文件都以以下格式运行
compiler.exe -dM -E - < NUL > output\compiler.txt
compiler
会是这样的
叮当声
或
或
g++
output
目录在我的系统上运行后
目录包含文件(警告:通过NDK确实有很多编译器可用):
aarch64-linux-android-c++.txt
aarch64-linux-android-cpp.txt
aarch64-linux-android-g++.txt
aarch64-linux-android-gcc-4.9.txt
aarch64-linux-android-gcc-4.9.x.txt
aarch64-linux-android-gcc.txt
arm-linux-androideabi-c++.txt
arm-linux-androideabi-cpp.txt
arm-linux-androideabi-g++.txt
arm-linux-androideabi-gcc-4.9.txt
arm-linux-androideabi-gcc-4.9.x.txt
arm-linux-androideabi-gcc.txt
clang++.txt
clang.txt
clang_32.txt
i686-linux-android-c++.txt
i686-linux-android-cpp.txt
i686-linux-android-g++.txt
i686-linux-android-gcc-4.9.txt
i686-linux-android-gcc-4.9.x.txt
i686-linux-android-gcc.txt
mips64el-linux-android-c++.txt
mips64el-linux-android-cpp.txt
mips64el-linux-android-g++.txt
mips64el-linux-android-gcc-4.9.txt
mips64el-linux-android-gcc-4.9.x.txt
mips64el-linux-android-gcc.txt
mipsel-linux-android-c++.txt
mipsel-linux-android-cpp.txt
mipsel-linux-android-g++.txt
mipsel-linux-android-gcc-4.9.txt
mipsel-linux-android-gcc-4.9.x.txt
mipsel-linux-android-gcc.txt
x86_64-linux-android-c++.txt
x86_64-linux-android-cpp.txt
x86_64-linux-android-g++.txt
x86_64-linux-android-gcc-4.9.txt
x86_64-linux-android-gcc-4.9.x.txt
x86_64-linux-android-gcc.txt
#define __DBL_MIN_EXP__ (-1021)
#define __UINT_LEAST16_MAX__ 65535
#define __ATOMIC_ACQUIRE 2
#define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F
#define __GCC_IEC_559_COMPLEX 2
#define __UINT_LEAST8_TYPE__ unsigned char
#define __INTMAX_C(c) c ## L
#define __CHAR_BIT__ 8
#define __UINT8_MAX__ 255
#define __ANDROID__ 1
#define __WINT_MAX__ 4294967295U
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __SIZE_MAX__ 18446744073709551615UL
#define __WCHAR_MAX__ 4294967295U
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
事实证明,这些文件中有许多是相同的,但它们之间存在显著差异
叮当声
和
通用条款