リチャードは正しいです。ほとんどのコンパイラは、-dM
コマンド(少なくともclang
とgcc
)をサポートしているようです。私の場合は、Androidビルドシステムによってどのプリプロセッサマクロが設定されているかを知りたいと思っていました。 Android NDKには多くのコンパイラが用意されているため、やや複雑です。何この
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)
をあなたはこのファイルを呼び出すと、「introspect.py」、そして使い方は単純
python introspect.py
次のとおりです。したがって、私は次のPythonを作成したマクロのすべてを保存するために3スクリプトがファイルに含まれますスクリプトは、コンパイラをどこかに入れるべきであるroot
ディレクトリ(私のシステムではC:\\Android\\android-sdk\\ndk-bundle\\toolchains\\
)の*.exe
ファイル(Linuxシステムの場合はこれを変更します)を探します。具体的には、このスクリプトは、名前で
[ "-ar", "-nm", "-ranlib", "filt", "-format", "-tidy" ]
でファイルを除く、名前に
[ "gcc", "g++", "clang", "c++", "cpp" ]
用語の一つですべての実行可能ファイルを探します。最後に、見つかった実行ファイルのそれぞれは、形式compiler
がclang
またはgcc
またはg++
ようになります
compiler.exe -dM -E - <NUL> output\compiler.txt
で実行されます。このスクリプトは、output
ディレクトリの作成を強制します。
それらのファイルの最初の数行が
のように見える傾向があり
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
:私のシステム上で実行した後、output
ディレクトリは、ファイル(:本当にNDKを介して利用可能なコンパイラがたくさんある警告)が含まれてい
#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
これらのファイルの多くは同じですが、clang
とgcc
ファイルには大きな違いがあります。
コンパイラに応じて、どのコンパイラ? –
今、私はAndroidのために何かをコンパイルしようとしているので、clangプロセッサを使用しています。しかし、私はいくつかの他のフラグを設定していると信じて、それはそれが使用しているフラグが文書化されて表示されません –
私はコンパイラのマクロをすべて印刷することができますシンプルな10行のC + +ファイルがあるのだろうか?私が使用したいコンパイラでこの単純なテストファイルをコンパイルし、フラグを取得してSwigに渡すという考えは、gccの場合は –