为什么clang需要-lm而不是gcc?
我遇到了一个奇怪的问题,我需要将-lm传递给clang,以便它编译代码:为什么clang需要-lm而不是gcc?,c,gcc,clang,gcc-warning,C,Gcc,Clang,Gcc Warning,我遇到了一个奇怪的问题,我需要将-lm传递给clang,以便它编译代码: 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;
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;
}
我注意到的一件重要的事情是,在这种情况下,gcc能够轻松超越clang,因为gcc内联函数调用,而clang不:
叮当声:
$ nm -g test
0000000000601048 B __bss_start
U conj@@GLIBC_2.2.5
...
通用条款:
我使用kubuntu 16.04。Clang3.8版本和5.4.0GCC版本
有没有办法对这些函数进行铿锵的内联调用?:
6.59 GCC提供的其他内置功能
GCC提供了大量的内置函数,而不是
如上所述。其中一些用于处理过程中的内部使用
例外情况或可变长度参数列表的列表,并且没有记录
这是因为它们可能会不时变化;我们不建议
这些函数的一般用法
其余的函数用于优化目的
ISO C99功能_Exit、acoshf、acoshl、acosh、asinhf、asinhl、,
asinh,atanhf,atanhl,atanh,cabsf,cabsl,cabs,cacosf,cacosf,
cacosh,cacosh,cacosl,cacos,cargf,cargl,carg,casinf,casinhf,
卡西尔,卡西,卡西尔,卡西,卡坦夫,卡坦夫,卡坦尔,卡坦夫,
卡坦,卡坦,cbrtf,cbrtl,cbrt,ccosf,ccoshf,ccoshl,ccosh,
ccosl、ccos、cexpf、cexpl、cexp、cimagf、cimagl、cimag、clogf、clogl、,
阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,
cpowl、cpow、cprojf、cprojl、cproj、crealf、creall、creal、csinf、,
csinhf、csinhl、csinh、csinl、csin、csqrtf、csqrtl、csqrt、ctanf、,
ctanhf,ctanhl,ctanh,ctanl,ctan,erfcf,erfcl,erfc,erff,erfl,
exp2f,exp2l,exp2,expm1f,expm1l,expm1,fdimf,fdiml,fdim,
fmaf,fmal,fmaxf,fmaxl,fmax,fma,fminf,fminl,fmin,FMF,
hypotl,hypot,ilogbf,ilogbl,ilogb,imaxabs,isblank,iswblank,
lgammaf,lgammal,lgamma,llabs,llrintf,llrintl,llrint,llroundf,
llround,llround,log1pf,log1pl,log1p,log2f,log2l,log2,logbf,
logbl,logb,lrintf,lrintl,lrint,lroundf,lroundl,lroundl,
nearbyintf,nearbyintl,nearbyint,nextafter,nextafter,nextafter,
nexttoward,nexttoward,nexttoward,remainder,remainder,
余数,remquof,remquol,remquo,rintf,rintl,rint,roundf,
圆形,圆形,scalblnf,scalblnl,scalbln,scalbnf,scalbnl,scalbn,
snprintf,tgammaf,tgammal,tgamma,truncf,truncl,trunc,vfscanf,
vscanf、vsnprintf和vsscanf作为内置函数处理,除了
在严格的ISO C90模式下(-ansi或-std=C90)
由于GCC提供了conj()
作为内置函数,因此在使用GCC编译时,您不需要在libm.so
(或libm.a
)中链接-lm
选项:
6.59 GCC提供的其他内置功能
GCC提供了大量的内置函数,而不是
如上所述。其中一些用于处理过程中的内部使用
例外情况或可变长度参数列表的列表,并且没有记录
这是因为它们可能会不时变化;我们不建议
这些函数的一般用法
其余的函数用于优化目的
ISO C99功能_Exit、acoshf、acoshl、acosh、asinhf、asinhl、,
asinh,atanhf,atanhl,atanh,cabsf,cabsl,cabs,cacosf,cacosf,
cacosh,cacosh,cacosl,cacos,cargf,cargl,carg,casinf,casinhf,
卡西尔,卡西,卡西尔,卡西,卡坦夫,卡坦夫,卡坦尔,卡坦夫,
卡坦,卡坦,cbrtf,cbrtl,cbrt,ccosf,ccoshf,ccoshl,ccosh,
ccosl、ccos、cexpf、cexpl、cexp、cimagf、cimagl、cimag、clogf、clogl、,
阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,阻塞,
cpowl、cpow、cprojf、cprojl、cproj、crealf、creall、creal、csinf、,
csinhf、csinhl、csinh、csinl、csin、csqrtf、csqrtl、csqrt、ctanf、,
ctanhf,ctanhl,ctanh,ctanl,ctan,erfcf,erfcl,erfc,erff,erfl,
exp2f,exp2l,exp2,expm1f,expm1l,expm1,fdimf,fdiml,fdim,
fmaf,fmal,fmaxf,fmaxl,fmax,fma,fminf,fminl,fmin,FMF,
hypotl,hypot,ilogbf,ilogbl,ilogb,imaxabs,isblank,iswblank,
lgammaf,lgammal,lgamma,llabs,llrintf,llrintl,llrint,llroundf,
llround,llround,log1pf,log1pl,log1p,log2f,log2l,log2,logbf,
logbl,logb,lrintf,lrintl,lrint,lroundf,lroundl,lroundl,
nearbyintf,nearbyintl,nearbyint,nextafter,nextafter,nextafter,
nexttoward,nexttoward,nexttoward,remainder,remainder,
余数,remquof,remquol,remquo,rintf,rintl,rint,roundf,
圆形,圆形,scalblnf,scalblnl,scalbln,scalbnf,scalbnl,scalbn,
snprintf,tgammaf,tgammal,tgamma,truncf,truncl,trunc,vfscanf,
vscanf、vsnprintf和vsscanf作为内置函数处理,除了
在严格的ISO C90模式下(-ansi或-std=C90)
由于GCC提供了
conj()
作为一个内置函数,您不需要在libm.so
(或libm.a
)中链接-lm
选项来使用GCC进行编译,因为它们是不同的编译器,并且具有不同的库实现?@AjayBrahmakshatriya这根本不是库的问题。它是一个GCC扩展-GCC提供了许多内置函数。@AndrewHenle by library我指的不是实际的lib(或其他)文件。我的意思是图书馆要用复数。一个通过内置实现,另一个通过函数调用实现。不过我用错了词。因为它们是不同的编译器,并且有不同的库实现?@AjayBrahmakshatriya这根本不是库的问题。它是一个GCC扩展-GCC提供了许多内置函数。@AndrewHenle by library我指的不是实际的lib(或其他)文件。我的意思是图书馆要用复数。一个通过内置实现,另一个通过函数调用实现。不过我用错了词。你知道如何让这些函数内联吗?我大量使用clang,在我的例子中,gcc在很多方面都优于clang,因为它内联了对这些函数的调用。@Goovie有关clang优化的一些信息,请参阅。我修改了这个测试,用“-O”重新编译
$ nm -g test
0000000000601048 B __bss_start
U conj@@GLIBC_2.2.5
...
$ nm -g test
0000000000601038 B __bss_start
...