Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<stdio.h> vs <math.h> - Why do you have to link one and not the other? [duplicate]

Tags:

c

I'm confused why you have to type -lm to properly link math to your code, but don't have to do the same for stdio. I've only just started using C, so I apologize if this is a stupid quesiton or I'm missing something obvious.

like image 952
Andrew0085 Avatar asked Jan 13 '23 17:01

Andrew0085


1 Answers

In short, because of historical reasons,

The functions in stdio.h are in libc, while the functions in math.h are in libm. libc is linked by default but libm isn't.

like image 114
Yu Hao Avatar answered Jan 31 '23 09:01

Yu Hao