Why do some LLVM standard library headers include other headers but GCC does not

Viewed 155

While making a project compile across both GCC and Clang, I've noticed that functions like fabs were causing compilation issues on GCC, since I had never included <cmath> myself. I was developing on Clang, so I never noticed this, since the llvm <cstdlib> header file I was using includes <cmath> itself, seemingly without doing anything with it, while the GCC version does not.

Is there any reason for this? and is there anything I can do to make sure my code will compile across multiple standard libraries besides just trying it?

1 Answers

For every function you use, consult the C++ reference to find out which header you should include.

The reference for fabs says that you have to include <cmath>.

Related