Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supporting linux/types.h OSX

Tags:

c++

macos

I am trying to cross compile an application using OSX. However, when I compile I get the following...

fatal error: 'linux/types.h' file not found

When I change to sys/types.h and now I get...

 error: unknown type name '__s32'
 unknown type name '__u8'
 unknown type name '__u16'
 etc

Can someone help me with how to handle this?

like image 372
Jackie Avatar asked Nov 30 '13 16:11

Jackie


2 Answers

Obviously a Linux-specific header file is not going to be present under MacOS/X, which is not Linux-based.

The easiest work-around for the problem would be to go through your program and replace all the instances of

#include "linux/types.h"

with this:

#include "my_linux_types.h"

... and write a new header file named my_linux_types.h and add it to your project; it would look something like this:

#ifndef my_linux_types_h
#define my_linux_types_h

#ifdef __linux__
# include "linux/types.h"
#else
# include <stdint.h>
typedef int32_t __s32;
typedef uint8_t __u8;
typedef uint16_t __u16;
[... and so on for whatever other types your program uses ...]
#endif

#endif
like image 71
Jeremy Friesner Avatar answered Oct 24 '22 06:10

Jeremy Friesner


Those headers are headers that the kernel uses. Probably, the problem is in the implementation and definitions of such header files across platforms (Linux vs Mac OS in our case) The POSIX definitions don't apply to the kernel, but rather to the system calls it exposes to the user space.

like image 1
Alex Avatar answered Oct 24 '22 06:10

Alex