Sometimes I see compiler complaining about this line
#include <sys/io.h>
with
fatal error: sys/io.h: No such file or directory
If I simply change it to
#include <sys/uio.h>
It will magically work. Can someone explain to me the difference? Why do some OSes have one but not the other?
Edit: This issue happens on a Linux, not just OS X.
Advertisement
Answer
Generally speaking, it is not safe or even sensible to simply change the name of a header file being included when the compiler cannot find that header. Headers with similar names do not necessarily have anything to do with each other.
That appears to be the case here: the GLIBC header file sys/io.h
does not declare the vectored I/O functions of the POSIX-specified header sys/uio.h
, at least not directly. In fact, GLIBC also provides sys/uio.h
. They’re different. Neither C nor POSIX provides any reason to believe that sys/uio.h
on one system would provide any declarations that are provided by a header named sys/io.h
on that or any other system.
If you are trying to build C code and some header cannot be found, then the first thing to consider is the include search path, and whether the header name needs a path segments added or removed. The next thing to consider is whether that header is needed at all in the build environment. If it is not, then changing the header to name some other header that is actually present will fix the build, but so would deleting the include
directive altogether.
I’d rate it better, in fact, to remove or comment out such a failing include
directive, make sure warnings are cranked up, and see what, if any, missing declarations the compiler then complains about. That will give you a handle with which to determine what header, if any, you should include in place of the missing one.