问题
I'd like to compile a c programm developed for linux using cc under os x.
It includes the header sys/io.h.
When compiling I get the error that this file could not be found?
Isn't there any sys/io.h header file under os x?
Any help would be really appreciated!
Thanks!
回答1:
Include instead.
or why not both?
#ifdef __APPLE__
#include
#else
#include
#endif
In case of Apple OS (OSX/iOS) the code will know compile with
回答2:
What bibor has written is perfect. Though my file looks something like this and works well.
#ifdef __linux
#include
#elseif __apple
#include
回答3:
$ ls /usr/include/sys/io.h
ls: /usr/include/sys/io.h: No such file or directory
It doesn't look like it. You may have to do some porting.
Linux has this header file. It looks like it has to do with low level port input and output.
In general, things in /usr/include/sys are going to be operating-system specific, so you'll have to port to a new architecture if it's not already ported.
回答4:
You can manually add it to your project, and it should compile.
https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/master/sysroot/usr/include/sys/io.h
Edit: You need features.h as well
https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/master/sysroot/usr/include/features.h
Finally got cursor support in my kernel, although the functions in io.h weren't working for me. They compiled fine, and may help someone else. This is the code I'm going forward with...
static inline void outb(unsigned short port, unsigned char value)
{
__asm__ __volatile__ ("outb %1, %0" : : "dN" (port), "a" (value));
}
static inline unsigned char inb(unsigned short port)
{
unsigned char value;
__asm__ __volatile__ ("inb %1, %0" : "=a"(value) : "Nd"(port));
return value;
}
void update_cursor(int row, int col)
{
unsigned short position=(row*80) + col;
// cursor LOW port to vga INDEX register
outb(0x3D4, 0x0F);
outb(0x3D5, (unsigned char)(position&0xFF));
// cursor HIGH port to vga INDEX register
outb(0x3D4, 0x0E);
outb(0x3D5, (unsigned char )((position>>8)&0xFF));
}
来源:https://stackoverflow.com/questions/2762010/osx-sys-io-h-not-found