나는 C 아주 새로운 그리고 난이 코드가 있습니다math.h 헤더를 포함해도 "sqrt에 대한 정의되지 않은 참조"오류가 발생하는 이유는 무엇입니까?
#include <stdio.h>
#include <math.h>
int main(void)
{
double x = 0.5;
double result = sqrt(x);
printf("The square root of %lf is %lf\n", x, result);
return 0;
}
을하지만 이것을 컴파일 할 때 :
gcc test.c -o test
나는 다음과 같은 오류가 발생합니다 :
/tmp/cc58XvyX.o: In function `main':
test.c:(.text+0x2f): undefined reference to `sqrt'
collect2: ld returned 1 exit status
왜 이런 일이 생길까요? sqrt()
은 math.h
헤더 파일에 없습니까? 내가 cosh
및 기타 삼각 함수와 같은 오류가 발생합니다. 왜?
그리고 왜 여기에'libm'이 표준 라이브러리의 일부를 포함하고 있지만 왜 왜 링크되어 있지 않은지에 대한 추측이 있습니다 : http://stackoverflow.com/questions/1033898/why-do-you-have- to-link-the-math-library-in-c –
이 라이브러리는 다음과 같습니다. http://stackoverflow.com/q/5248919/694576 – alk