Message "unknown type name 'uint8_t'" in MinGW

CWindowsMingw

C Problem Overview


I get "unknown type name 'uint8_t'" and others like it using C in MinGW.

How can I solve this?

C Solutions


Solution 1 - C

Try including stdint.h or inttypes.h.

Solution 2 - C

To use the uint8_t type alias, you have to include the stdint.h standard header.

Solution 3 - C

To be clear: If the order of your #includes matters and it is not part of your design pattern (read: you don't know why), then you need to rethink your design. Most likely, this just means you need to add the #include to the header file causing problems.

At this point, I have little interest in discussing/defending the merits of the example, but I will leave it up as it illustrates some nuances in the compilation process and why they result in errors.


You need to #include the stdint.h before you #include any other library interfaces that need it.

Example:

My LCD library uses uint8_t types. I wrote my library with an interface (Display.h) and an implementation (Display.c).

In display.c, I have the following includes.

#include <stdint.h>
#include <string.h>
#include <avr/io.h>
#include <Display.h>
#include <GlobalTime.h>

And this works.

However, if I rearrange them like so:

#include <string.h>
#include <avr/io.h>
#include <Display.h>
#include <GlobalTime.h>
#include <stdint.h>

I get the error you describe. This is because Display.h needs things from stdint.h, but it can't access it because that information is compiled after Display.h is compiled.

So move stdint.h above any library that needs it and you shouldn't get the error any more.

Solution 4 - C

I had to include "PROJECT_NAME/osdep.h" and that includes the OS-specific configurations.

I would look in other files using the types you are interested in and find where/how they are defined (by looking at includes).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobotRockView Question on Stackoverflow
Solution 1 - CcnicutarView Answer on Stackoverflow
Solution 2 - CouahView Answer on Stackoverflow
Solution 3 - CLanchPadView Answer on Stackoverflow
Solution 4 - CJohn bView Answer on Stackoverflow