1

I've been trying to start my project out split into multiple files, knowing it will grow. I was templating it off of how I've done C++ files in the past: classes in an individual .h/.cpp pair and linked into the main file. I'm using the OneBitDisplay library for my OLEDs. When I include the library in my ino file and call functions within it, all works fine. When I have it linked from one of my class header files, it gives this output:

In file included from C:\Users\Kyle\Documents\Arduino\libraries\OneBitDisplay-master\src/OneBitDisplay.h:4:0,
                 from C:\Users\Kyle\Projects\EOS-OSC\OLED.h:1,
                 from C:\Users\Kyle\Projects\EOS-OSC\OLED.cpp:1:
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:67:1: error: 'uint8_t' does not name a type
 uint8_t iSDA, iSCL; // pin numbers (0xff = disabled)
 ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:68:1: error: 'uint8_t' does not name a type
 uint8_t bWire; // use the Wire library
 ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:69:1: error: 'uint8_t' does not name a type
 uint8_t iSDABit, iSCLBit; // bit numbers of the ports
 ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:70:1: error: 'uint32_t' does not name a type; did you mean 'char32_t'?
 uint32_t iDelay;
 ^~~~~~~~
 char32_t
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:75:10: error: 'uint32_t' does not name a type; did you mean 'char32_t'?
 volatile uint32_t *pSDADDR, *pSDAPORT; // data direction and port register addr
          ^~~~~~~~
          char32_t
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:76:10: error: 'uint32_t' does not name a type; did you mean 'char32_t'?
 volatile uint32_t *pSCLDDR, *pSCLPORT;
          ^~~~~~~~
          char32_t
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:82:26: error: 'uint8_t' has not been declared
 int I2CRead(BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen);
                          ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:82:41: error: 'uint8_t' has not been declared
 int I2CRead(BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen);
                                         ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:86:34: error: 'uint8_t' has not been declared
 int I2CReadRegister(BBI2C *pI2C, uint8_t iAddr, uint8_t u8Register, uint8_t *pData, int iLen);
                                  ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:86:49: error: 'uint8_t' has not been declared
 int I2CReadRegister(BBI2C *pI2C, uint8_t iAddr, uint8_t u8Register, uint8_t *pData, int iLen);
                                                 ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:86:69: error: 'uint8_t' has not been declared
 int I2CReadRegister(BBI2C *pI2C, uint8_t iAddr, uint8_t u8Register, uint8_t *pData, int iLen);
                                                                     ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:92:27: error: 'uint8_t' has not been declared
 int I2CWrite(BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen);
                           ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:92:42: error: 'uint8_t' has not been declared
 int I2CWrite(BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen);
                                          ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:100:1: error: 'uint8_t' does not name a type
 uint8_t I2CTest(BBI2C *pI2C, uint8_t addr);
 ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:104:27: error: 'uint8_t' has not been declared
 void I2CScan(BBI2C *pI2C, uint8_t *pMap);
                           ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:110:27: error: 'uint32_t' has not been declared
 void I2CInit(BBI2C *pI2C, uint32_t iClock);
                           ^~~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:115:36: error: 'uint8_t' has not been declared
 int I2CDiscoverDevice(BBI2C *pI2C, uint8_t i);
...

This keeps going for quite a while where any types from the stdint library are referenced. It seems to only occur when the library is included in a header file, not when it is in the main ino sketch. I have it linked in the ino, knowing that the compiler needs all referenced libraries placed there. When I remove the include from the header, it gives errors that it can't find types for variables that I've declared (as it should, given that these types are defined in the library I'm trying to include)

Any clues? I've never posted anything on StackOverflow, because I usually can find the answer but this one has stumped me. I'm happy to provide any other code or debugging output if needed.

2
  • In Oled.cpp (or Oled.h), try including Arduino.h before any other includes.
    – PMF
    Jan 24, 2022 at 6:14
  • That did it. Thanks. I had them in there, just needed to have Arduino.h before everything else. Makes sense, dependency-wise. Just a bit strange because looking at the source code the libraries already include Arduino.h themselves. Must have to do with the way Arduino searches for dependencies. Jan 24, 2022 at 14:16

2 Answers 2

1

The uint8_t and the uint32_t types reported in your compile errors are defined in the stdint.h file. In .ino the stdint.h is included with Arduino.h (which is added at ino to cpp conversion by Arduino builder).

The BitBang_I2C.h should include Arduino.h or stdint.h, but the author forgot to add it. Then if BitBang_I2C.h is included in .ino, the Arduino.h is included above it and the types are defined, but if you include BitBang_I2C.h in a cpp file which doesn't include Arduino.h or stdint.h, then the stdint defines are missing.

The workaround for this bug is to add #include <stdint.h> at the top of your OLED.cpp file.

1
  • Thanks. I had included both Arduino.h and stdint.h, but it looks like I had them out of order. Feels kinda stupid now 😂 Jan 24, 2022 at 14:15
1

Arduino IDE implicitly includes some headers. Especially "arduino.h".
You need to include "stdint.h" into your header files for completeness.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.