私はそれがコードをコンパイルするために打ち鳴らすために-lmを渡す必要がある奇妙な問題に遭遇しました:なぜclangはgccと違って-lmを必要としますか?
gcc test.c -o test #works
clang test.c -o test #doesn't work
clang -lm test.c -o test #works
#include <stdio.h>
#include <complex.h>
int main() {
double complex z = 1.0 + 3.0 * I;
double complex conjugate = conj(z);
printf("The conjugate of Z is = %.2f %+.2fi\n", creal(conjugate), cimag(conjugate));
return 0;
}
具体的には、リンカエラーがあります:
/tmp/test-561678.o: In function `main':
test.c:(.text+0x4a): undefined reference to `conj'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
重要なもの私が気づいたことは、この場合のGCCで打ち鳴らすにはないのに対し、gccのインライン通話機能するので、簡単に打ち鳴らすをアウトパフォームすることが可能であることである:
打ち鳴らす:
$ nm -g test
0000000000601048 B __bss_start
U [email protected]@GLIBC_2.2.5
...
GCC:
$ nm -g test
0000000000601038 B __bss_start
...
私はKubuntuの16.04を使用しています。 Clang 3.8バージョン、および5.4.0 gccバージョンです。
これらの機能をclangインラインで呼び出す方法はありますか?
でコンパイル異なるコンパイラであり、ライブラリの実装が異なりますか? –
@AjayBrahmakshatriyaこれは図書館の問題ではありません。それはGCC拡張です - GCCは多くの組み込み関数を提供します。 –
@AndrewHenle by library私は実際のlib(またはそれ)のファイルを意味しませんでした。私は、ライブラリが複素数を使用することを意味しました。 1つは組み込み関数を使用して実装し、もう1つは関数呼び出しを使用して実装します。私は間違った言葉を使った。 –