Errors for uint8_t, int32_t and int16_t in included library files

Hi,

I am seeing compile errors related to uint8_t, int32_t and int16_t type definitions in a library that I’m trying to include in my main source file:

In file included from src/main.cpp:1:0:
.piolibdeps/XLR8Quadrature_ID1855/src/XLR8Quadrature.h:76:3: error: ‘uint8_t’ does not name a type
uint8_t sample_rate;
^
.piolibdeps/XLR8Quadrature_ID1855/src/XLR8Quadrature.h:92:5: error: ‘int32_t’ does not name a type
int32_t readCount();
^
.piolibdeps/XLR8Quadrature_ID1855/src/XLR8Quadrature.h:93:5: error: ‘int16_t’ does not name a type
int16_t readRate();
^
.piolibdeps/XLR8Quadrature_ID1855/src/XLR8Quadrature.h:96:5: error: ‘uint8_t’ does not name a type
uint8_t quadratureIndex;

If I use those type definitions in main.cpp, I don’t see errors, but I get them in the included file. I have tried moving the library to my local /lib directory and also putting the .h and .cpp files directly in the src/ directory. No luck.

Here are the settings from my platformio.ini file:

[env:alorium_sno]
platform = atmelavr
board = alorium_sno
framework = arduino
board_build.f_cpu = 32000000L ; change MCU frequency
lib_archive = false
monitor_speed = 115200
lib_deps = XLR8Quadrature, KMeans

Any suggestions?

Thanks!
Jason

#include <stdint.h> (or directly Arduino.h, it includes it) as the first line in your main.cpp or fix the XLR8Quadrature.h file which is trying to declare functions without pulling in stdint.h first.

1 Like

Thanks for the recommendation. That did indeed work.

Though, it’s somewhat curious, IMO. The fact that the types are not a problem in the main.cpp led me to believe that stdint.h was being included somewhere in the framework setup by PlatformIO. So, I was expecting it to apply to includes, as well.

Though, admittedly, I don’t really understand what’s going on under the hood very well.

Thanks for your help!
Jason

The problem is within the XLR8Quadrature/XLR8Quadrature.h at master · AloriumTechnology/XLR8Quadrature · GitHub file and partly in the Arduino IDE

  • the XLR8Quadrature.h uses uint8_t etc from stdint.h but does not #include this header file first; that’s an error, it should #include <stdint.h> or #include <Arduino.h> first
  • this will still work in the Arduino IDE because it automatically places the line #include <Arduino.h> as the first line in your sketch without you seeing it. Thus when the program does
#include <Arduino.h> //auto-gened by Arduino-IDE
#include "XLR8Quadrature.h"
  • the uint8_t types etc are pulled in correctly before the XLR8Quadrature.h header is and thus compiles
  • since you’re using a main.cpp file and not a main.ino file, you must take care that you #include <Arduino.h> as the first thing. If you first do #include "XLR8Quadrature.h" then the needed types won’t exist; if you had named your file main.ino then PIO would have auto-included Arduino.h for you and it would have worked, too.

For more see Redirecting....

Ah… Ok. I see. Thanks!

J

In the spirit of Full Disclosure, I want to share that I just realized I had done something very foolish.

When I created my new project from the PlatformIO Home page and then opened the resulting main.cpp file, the first thing I did was Select-All, Delete. I did so because I had code from another project that I wanted to paste into the file.

What I just realized is that the template code added to main.cpp when the project is created is:

#include <Arduino.h>

void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}

The first #include being the most important - as it relates to the issue I saw with the compile.

So, had I been paying attention, I’d have noticed that Arduino.h was included for me. My bad!

I apologize for wasting everyone’s time. Sigh…

Jason