2017-09-19 3 views
0

Swigを使用して大規模なC++プロジェクト用のインタフェースファイルを生成しようとしています。プロジェクトのヘッダーファイルは、コンパイラタイプに基づいていくつかのチェックを行います。たとえば、Swigのコンパイラフラグを設定する

#if defined(__clang__) 
    ... 
#if defined(__llvm__) 

コンパイラフラグをSwigに渡す必要があります。具体的には、私はこのようなSWIG呼び出す必要がありますように私には思える:

swig -D__clang__ ... 

はしかし、これは私はまだ同じエラーを取得するので、私は取得していますエラーメッセージを軽減していないようです。

私はコンパイラフラグを間違って設定しているかどうか、またはすべてのコンパイラフラグを設定していないかどうかはわかりません。そこで質問は2つあり:

  1. 私は

    がぶ飲み-D__clang__を呼び出すことにより、正しくコンパイラフラグを設定アム...... xxx.i

または私は何とか定義する必要がありますこれらのパラメータはxxx.iインタフェースファイルにありますか?

  1. コンパイラのフラグをすべてキャプチャするにはどうすればよいですか?私は確かに私のマシン上でC++コードをコンパイルすることができますが、どのマクロがコンパイラによって設定されているのかを知るにはどうすればいいですか?これを行う一般的な方法はありますか?
+0

コンパイラに応じて、どのコンパイラ? –

+0

今、私はAndroidのために何かをコンパイルしようとしているので、clangプロセッサを使用しています。しかし、私はいくつかの他のフラグを設定していると信じて、それはそれが使用しているフラグが文書化されて表示されません –

+0

私はコンパイラのマクロをすべて印刷することができますシンプルな10行のC + +ファイルがあるのだろうか?私が使用したいコンパイラでこの単純なテストファイルをコンパイルし、フラグを取得してSwigに渡すという考えは、gccの場合は –

答えて

0

リチャードは正しいです。ほとんどのコンパイラは、-dMコマンド(少なくともclanggcc)をサポートしているようです。私の場合は、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" ] 

用語の一つですべての実行可能ファイルを探します。最後に、見つかった実行ファイルのそれぞれは、形式compilerclangまたは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 

これらのファイルの多くは同じですが、clanggccファイルには大きな違いがあります。

0

生成するインターフェイスを定義する.iファイルが必要です。

ここでは、単に#define __clang__を使用できます。例えば

、そのSWIGは、すべてのコンパイラフラグは必要ありませんのでご注意また鉱山https://bitbucket.org/binarno/imebra/src/db648a8b9c359524d40fd7d63c785b6269147010/wrappers/swig.i?at=default

のライブラリーのためのswig.iファイルを見てみましょう:あなたのプロジェクトをコンパイルするつもりはないが、それはちょうどます追加のcxxファイルを生成します。 .iファイルで、swigが正しいクラスとメソッドを選択できるようにするフラグ(必要な場合)を宣言するだけです。

関連する問題