我想編寫一個簡單的C90代碼利用數學庫C90代碼:鏈接數學庫使用GCC
的main.c:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
printf("M_PI: %f\n", M_PI);
}
我使用GCC編譯器和使用選項 - ansi -pedantic強制執行C90標準。
gcc -ansi -pedantic -lm main.c
但它不編譯。以下是錯誤信息:
main.c: In function ‘main’:
main.c:7:25: error: ‘M_PI’ undeclared (first use in this function)
main.c:7:25: note: each undeclared identifier is reported only once for each function it appears in
我的問題是,爲什麼? C90標準是否禁止使用數學庫?