如果我包含<stdlib.h>或<stdio.h>在C程序中,我不必在编译时链接这些,但我必须链接到<math.h>,使用-lmgcc,例如:
gcc test.c -o test -lm
Run Code Online (Sandbox Code Playgroud)
这是什么原因?为什么我必须显式链接数学库而不是其他库?
I am trying to run the following test program on my Solaris 10 sparc machine using gcc 5.5.0
#include <iostream>
#include <cmath>
int main()
{
std::cout << "exp2(4) = " << std::exp2(4) << '\n'
<< "exp2(0.5) = " << std::exp2(0.5) << '\n'
<< "exp2(-4) = " << std::exp2(-4) << '\n';
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Here are the OS details,
~$ uname -a
SunOS sovms577 5.10 Generic_147147-26 sun4v sparc SUNW,SPARC-Enterprise-T5220
~$ cat /etc/release
Oracle Solaris 10 1/13 s10s_u11wos_24a SPARC
Copyright (c) 1983, …Run Code Online (Sandbox Code Playgroud)