Error: "reference to 'byte' is ambiguous" issue using VSCode, PlatformIO, macOS 13.5.1

graydetroit

Well-known member
Hi, I have a project which was previously compiling just fine on my MacBook Pro, but my computer had to be wiped so I've had to reinstall everything.

I'm using VSCode, PlatformIO, a Teensy 4.1, and my MacBook Pro is running on macOS 13.5.1.

It appears that something has seemed to cause a persistent error which prevents my project from compiling via the PlatformIO extension in VSCode, all the errors are related to the most prevalent error, namely "reference to 'byte' is ambiguous".

I'm able to compile and upload the simple Blink.ino sketch via the Arduino IDE, however.

Does anyone have any idea why I might be seeing this error or where to start looking to figure this out?

Thanks in advance.
 
Nobody is going to be able to work it out from this.
Post the full compiler error log and at least some source code that demonstrates the problem.
 
Is there a #include <Arduino.h> at the top?
First thought I had on reading ... didn't post, if not used in code before, it is a diff in PIO setup issue ... but when that doesn't get included the simplest things like 'byte' are undefined
 
Another thought: are you putting using namespace std; in your code? (I recommend against doing this.) If so, that might be another reason why byte is conflicting. One is defined by Arduino and another is std::byte.
 
Another thought: are you putting using namespace std; in your code?
No, I'm not.
Is there a #include <Arduino.h> at the top?
Yes, i'm including the Arduino header.

I'm kind of thinking it might be something with the way PlatformIO is caching or scanning for dependencies out of order or some sort of linker error after trying to compile the project from scratch after cloning the repository locally on the new machine.

Apologies for not posting enough information, It's a massive project right now that is private. Was kinda just hoping for pointers on where to look. Thanks for all the help so far.
 
Here is a portion of the compiler output:


Code:
In file included from src/XRAsyncIO.cpp:1:
include/XRAsyncIO.h:62:9: error: reference to 'byte' is ambiguous
   62 |         byte buffer[ASYNC_IO_W_BUFFER_SIZE];
      |         ^~~~
In file included from /Users/jamesgray/.platformio/packages/framework-arduinoteensy/cores/teensy4/inplace_function.h:37,
                 from /Users/jamesgray/.platformio/packages/framework-arduinoteensy/cores/teensy4/WProgram.h:51,
                 from /Users/jamesgray/.platformio/packages/framework-arduinoteensy/cores/teensy4/Arduino.h:6,
                 from include/XRAsyncIO.h:4,
                 from src/XRAsyncIO.cpp:1:
/Users/jamesgray/.platformio/packages/toolchain-gccarmnoneeabi-teensy/arm-none-eabi/include/c++/11.3.1/cstddef:69:14: note: candidates are: 'enum class std::byte'
   69 |   enum class byte : unsigned char {};
      |              ^~~~
In file included from /Users/jamesgray/.platformio/packages/framework-arduinoteensy/cores/teensy4/WProgram.h:46,
                 from /Users/jamesgray/.platformio/packages/framework-arduinoteensy/cores/teensy4/Arduino.h:6,
                 from include/XRAsyncIO.h:4,
                 from src/XRAsyncIO.cpp:1:
/Users/jamesgray/.platformio/packages/framework-arduinoteensy/cores/teensy4/wiring.h:219:17: note:                 'typedef uint8_t byte'
  219 | typedef uint8_t byte;
      |                 ^~~~
 
Ok, I was able to compile by using uint8_t, but since my project uses the Keypad library, I had to also change Keypad to use uint8_t instead of byte too. Thanks for the tip, I'm very much not sure why this issue is happening now vs. before, but glad I can at least compile.
 
Sorry, I am not a up to date c++ person... I started programming back in the 70s...

But taking a guess, do you have something in some global header like:
Code:
using namespace std;

My guess is that is being used somewhere...
Otherwise, I don't think there would be a conflict. Could be wrong,
 
No I am not using the std namespace anywhere in my own code, as I mentioned above, BUT I just found that some library code indeed IS using the std namespace! But why was this not presenting a problem for so long up until now? Very strange, but thank you for suggesting this again because I didn't initially think to look into the library code, my bad.
 
It’s not a problem to use the std namespace. It’s a problem when there’s using namespace std; somewhere that also uses byte.
 
Back
Top