C unknown type '__u8'

I'm trying to compile a Linux program and am getting a number of errors in the form 'unknown type '__u8' or '__u16' or '__u32'.

Anyone come across and know what to do about it?
 
From the first Google match for __u8 type:

uintn_t are typedefs specified* by C99 (in <stdint.h>) and C++11 (in <cstdint>) standards. All new compilers provide these and appropriate definition is easy to get for the few ancient ones easily, so for portability always use this.

__un are Linux-specific typedefs predating those standards. They are not portable. The double underscore is used to signify a non-standard definition.

If possible I suspect the most simple fix would be something like -

Code:
typedef uint8_t __u8
typedef uint16_t __u16
typedef uint32_t __u32
I'm not a C programmer so the syntax above might not be right, and I'm assuming FreeBSD has uintX_t types based on the above quote. Also better would be to put this in some sort of #ifdef block that only applies if these are missing, or it detects FreeBSD, which is the sort of thing normally done if you want to make something portable. Ideally of course the original software should be updated to use standard types rather than something Linux specific.

If the software is written for Linux though, and has portability issues as simple to avoid as using Linux only integer types, you may find all sorts of other Linux-isms, some of which may not have an easy fix
 
I could work out how to use typedef but as a result of your suggestion changed all references in the code in line with the above and it proceeded OK until it need a
#include <linux/types.h>

Presumably there is some way to install Linux header files, but I don't know how...
 
I don't know how to install Linux header files. But for just one file, I wouldn't bother. It's much faster to do a quick hack: Change your source code to replace "#include <linux/types.h>" with "#include <mylinuxtypes.h>", and write a tiny header file in your project or directory that contains just the few types you really need. Or log in to a random Linux machine or look on the web, and make a copy of types.h from there; problem with that suggestion: that file probably includes another huge series of files, which end up being platform-specific, so you may have to copy a lot of other files there.

I think the best suggestion is actually to make the code portable, and you are already on the way there. You already fixed all the instances of __u8. Just remove the "#include <linux/types.h>", find out what breaks next, and fix it. When you are done, you'll have a non-Linux specific version of the source code.

If you want to do the world a favor: post the version somewhere. Perhaps it is an open source project, and you can feed your changes back to it? Or you can make it into a FreeBSD port? Or perhaps you can put it up on GitHub or such, so people can see it?
 
  1. Make a backup copy of the source folder (if necessary pkg install clone)
    clone path/to/src path/to/src.back

  2. cd path/to/src
    find . -name "*.c" -print0 | xargs -0 sed -e 's/__u8/uint8_t/g' -i ""
    find . -name "*.h" -print0 | xargs -0 sed -e 's/__u8/uint8_t/g' -i ""
 
Back
Top