PlatformIO on VSC Build Error

Hi guys,

I need your help :slight_smile:
Until now, I was using Atom with the PlatformIO extension to build my project.
But I would like to switch to Visual Studio Code, as I prefer the editor. I saw that the PlatformIO extension for VSC had made big steps forward, so I tried to switch today.

First of all, I want to say, that my project is completely working in Atom. I can build and upload it to the device.
The target is a Arduino Mega 2560 compatible board (Atmega 2560).

My project structure is quite simple.
Besides the main.cpp/h files, I packed everything is libraries. I am using 14 libs. All are placed in the libs folder and the suggested structure.

I am not sure if it’s directly related to the project.
On the one hand, I’ve created a small test project within VSC. This project can be build.
But on the other hand the project is compiling in Atom.

I am just getting an cryptic error message:

avr-g++ -o .pioenvs\megaatmega2560\FrameworkArduino\HardwareSerial1.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -g -Os -Wall -ffuncti
on-sections -fdata-sections -flto -mmcu=atmega2560 -DF_CPU=16000000L -DPLATFORMIO=30500 -DARDUINO_ARCH_AVR -DARDUINO_AVR_MEGA2560 -DARDUINO=10619 -IC:\Users\pho
ef\.platformio\packages\framework-arduinoavr\cores\arduino -IC:\Users\phoef\.platformio\packages\framework-arduinoavr\variants\mega C:\Users\phoef\.platformio\p
ackages\framework-arduinoavr\cores\arduino\HardwareSerial1.cpp
avr-g++ -o .pioenvs\megaatmega2560\FrameworkArduino\HardwareSerial2.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -g -Os -Wall -ffuncti
on-sections -fdata-sections -flto -mmcu=atmega2560 -DF_CPU=16000000L -DPLATFORMIO=30500 -DARDUINO_ARCH_AVR -DARDUINO_AVR_MEGA2560 -DARDUINO=10619 -IC:\Users\pho
ef\.platformio\packages\framework-arduinoavr\cores\arduino -IC:\Users\phoef\.platformio\packages\framework-arduinoavr\variants\mega C:\Users\phoef\.platformio\p
ackages\framework-arduinoavr\cores\arduino\HardwareSerial2.cpp
Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python27\Lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\util.py", line 92, in run
    self.outcallback(line)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\managers\platform.py", line 382, in on_run_out
    self._echo_line(line, level=1)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\managers\platform.py", line 397, in _echo_line
    click.secho(line, fg=fg, err=level > 1)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\termui.py", line 417, in secho
    return echo(style(text, **styles), file=file, nl=nl, err=err, color=color)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\utils.py", line 314, in echo
    file.write(message)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\_compat.py", line 560, in _safe_write
    return _write(s)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\_compat.py", line 97, in write
    return self.buffer.write(str(x))
IOError: [Errno 0] Error

PlatformIO extension and core are of course up to date.

pio upgrade
You're up-to-date!
PlatformIO 3.5.0a4 is currently the newest version available.

Python is also up to date (2.7.13).

I even get this error, when trying to update pio:

pio update
Updating tool-scons                      @ 3.20501.2      [Up-to-date]
Updating tool-unity                      @ 1.20302.1      [Up-to-date]
Updating pysite-pioplus                  @ 0.4.2          [Up-to-date]
Updating contrib-piohome                 @ 0.1.2          [Up-to-date]
Updating tool-pioplus                    @ 0.10.2         [Up-to-date]

Platform Manager
================
Platform Atmel AVR
--------
Updating atmelavr                        @ 1.7.0          [Up-to-date]
Updating toolchain-atmelavr              @ 1.40902.0      [Up-to-date]Error: Traceback (most recent call last):
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\__main__.py", line 104, in main
    cli(None, None, None)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\core.py", line 680, in main
    rv = self.invoke(ctx)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\decorators.py", line 16, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\commands\update.py", line 46, in cli
    ctx.invoke(cmd_platform_update, only_check=only_check)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\commands\platform.py", line 376, in platform_update
    platform, only_packages=only_packages, only_check=only_check)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\managers\platform.py", line 125, in update
    p.update_packages(only_check)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\managers\platform.py", line 286, in update_packages
    self.pm.update(manifest['__pkg_dir'], version, only_check)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\managers\package.py", line 722, in update
    click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\utils.py", line 314, in echo
    file.write(message)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\_compat.py", line 560, in _safe_write
    return _write(s)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\_compat.py", line 97, in write
    return self.buffer.write(str(x))
IOError: [Errno 0] Error

============================================================

An unexpected error occurred. Further steps:

* Verify that you have the latest version of PlatformIO using
  `pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  http://docs.platformio.org/page/faq.html

* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues

============================================================

Any ideas, how I can fix this error?

Thanks in advance

Yes, we will ask developers about moving to VSCode. We will still support both extensions, including for Atom. Nevertheless, PlatformIO IDE for VSCode has better integration particularly related to IntelliSense features (code completion, code navigation, etc).

Strange issue. Do you use the latest VSCode? Also, could click on Terminal icon on toolbar (bottom, left corner) and type pio run. Does it work?

Thanks for your quick reply.

Yes, I updated VSCode yesterday.

One thing comes right now to my mind. With the latest release of VSCode a x64 version is available:

I switched to the 64bit version.
Could this cause the problem?

I am using Windows 10 64bit.

Running the pio run from terminal results in the same error.

It’s very strange. I tried building the project about a thousand times, and now it has worked for the first time.

.
.
.
 Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python27\Lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\util.py", line 92, in run
    self.outcallback(line)
  File "C:\Users\phoef\.platformio\platforms\atmelavr\platform.py", line 47, in on_run_err
    PlatformBase.on_run_err(self, line)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\managers\platform.py", line 386, in on_run_err
    self._echo_line(line, level=3 if is_error else 2)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\managers\platform.py", line 397, in _echo_line
    click.secho(line, fg=fg, err=level > 1)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\termui.py", line 417, in secho
    return echo(style(text, **styles), file=file, nl=nl, err=err, color=color)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\utils.py", line 314, in echo
    file.write(message)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\_compat.py", line 560, in _safe_write
    return _write(s)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 166, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\_compat.py", line 97, in write
    return self.buffer.write(str(x))
IOError: [Errno 0] Error

Indexing .pioenvs\megaatmega2560\lib\libAngleSensor.a
Archiving .pioenvs\megaatmega2560\lib\libLadderCalculator.a
Archiving .pioenvs\megaatmega2560\lib\libMPU6050.a
Compiling .pioenvs\megaatmega2560\lib\Pixels\Pixels.o
Indexing .pioenvs\megaatmega2560\lib\libLadderCalculator.a
Indexing .pioenvs\megaatmega2560\lib\libMPU6050.a
Archiving .pioenvs\megaatmega2560\lib\libCommandInterface.a
Compiling .pioenvs\megaatmega2560\lib\ALFPower\ALFPower.o
Indexing .pioenvs\megaatmega2560\lib\libCommandInterface.a
Compiling .pioenvs\megaatmega2560\lib\Button\Button.o
Archiving .pioenvs\megaatmega2560\lib\libALFPower.a
Indexing .pioenvs\megaatmega2560\lib\libALFPower.a
Archiving .pioenvs\megaatmega2560\lib\libButton.a
Compiling .pioenvs\megaatmega2560\lib\Buzzer\Buzzer.o
Indexing .pioenvs\megaatmega2560\lib\libButton.a
Archiving .pioenvs\megaatmega2560\lib\libBuzzer.a
Archiving .pioenvs\megaatmega2560\lib\libPixels.a
Indexing .pioenvs\megaatmega2560\lib\libBuzzer.a
Indexing .pioenvs\megaatmega2560\lib\libPixels.a
Linking .pioenvs\megaatmega2560\firmware.elf
Building .pioenvs\megaatmega2560\firmware.hex
Calculating size .pioenvs\megaatmega2560\firmware.elf
AVR Memory Usage
----------------
Device: atmega2560

Program:  118944 bytes (45.4% Full)
(.text + .data + .bootloader)

Data:       4127 bytes (50.4% Full)
(.data + .bss + .noinit)


================================================================= [SUCCESS] Took 7.84 seconds =================================================================

I didn’t change anything.
No idea why it was working now.
Cleaning and building the project again results again in the same error.

I was also trying running VSCode as Administrator - same issue.

I am also wondering as VSCode does not recognize all classes in the libs folder.
For example I have a class handling the buttons and VSCode says the the identifier Button is undefined.
But it is defined for sure. And the build worked right before, despite this message.
Also functions like wdt_enable() and wdt_reset() from the AVR package are not recognized.

Any help is appreciated :slight_smile:
If you like, we can also set up a TeamViewer meeting to provide more insights …

Thanks for your help

I switched to vscode, but the problems I had were due to atom. But what I did find helpful was getting rid of the directories .platformio in /Users/UserName . It will repopulate the next time you load vscode and are in a platformio project.

thanks for your reply.
Unfortunately this did not resolve the problem. I get still the same error message.
Maybe something is wrong with my project? Anything I can do fundamentally wrong?

I’ve tried building up the project piece by piece by adding one lib at a time.
But still I cannot figure out whether the problem is related to a particular library or code passage of the project.

Does anybody has an idea how to isolate the problem?
Could it be related to the size of the project?

Any help is appreciated :slight_smile:
thanks

Any ideas?
Is there any debug log or something I can activate to better understand the problem? Is it possible to debug the code itself?

We recently updated our extension to 0.7.2. Could try it out?

Hallo Ivan,

thanks for your reply.
I just updated the VSCode extension and the Atmel AVR platform to the latest version.

Compiling .pioenvs\megaatmega2560\src\main.o
Archiving .pioenvs\megaatmega2560\libFrameworkArduinoVariant.a
Compiling .pioenvs\megaatmega2560\FrameworkArduino\CDC.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\HardwareSerial.o
Indexing .pioenvs\megaatmega2560\libFrameworkArduinoVariant.a

Unfortunately I still get the same error:
    Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python27\Lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\util.py", line 93, in run
    self.outcallback(line)
  File "C:\Users\phoef\.platformio\platforms\atmelavr\platform.py", line 47, in on_run_err
    PlatformBase.on_run_err(self, line)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\managers\platform.py", line 386, in on_run_err
    self._echo_line(line, level=3 if is_error else 2)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\platformio\managers\platform.py", line 397, in _echo_line
    click.secho(line, fg=fg, err=level > 1)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\termui.py", line 417, in secho
    return echo(style(text, **styles), file=file, nl=nl, err=err, color=color)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\utils.py", line 314, in echo
    file.write(message)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\_compat.py", line 560, in _safe_write
    return _write(s)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 166, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "c:\users\phoef\.platformio\penv\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
  File "c:\users\phoef\.platformio\penv\lib\site-packages\click\_compat.py", line 97, in write
    return self.buffer.write(str(x))
IOError: [Errno 0] Error

Compiling .pioenvs\megaatmega2560\FrameworkArduino\HardwareSerial0.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\HardwareSerial1.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\HardwareSerial2.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\HardwareSerial3.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\IPAddress.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\PluggableUSB.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\Print.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\Stream.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\Tone.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\USBCore.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\WInterrupts.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\WMath.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\WString.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\_wiring_pulse.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\abi.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\hooks.o
Compiling .pioenvs\megaatmega2560\FrameworkArduino\main.o

It’s interesting, that some classes are going to be compiled, but at some point it stuck. But obviously the compiler does not halt due to the error. After the exception occurs in the log, several classes are compiled.

Is there anything else I could try?

Thanks

Fixed in the latest development version. Please upgrade to PIO Core 3.5.0a9: Menu: Tasks > Run > Upgrade PlatformIO Core

Does it work now?

1 Like

Hallo Ivan,

I updated Pio Core:

pio --version
PlatformIO, version 3.5.0a9

The build is working without any issues!! Thanks a lot.

Best