I cannot build via pio.exe, but I can run avr-g++ manually

I have just installed PlatformIO (under Windows 10), and am trying to compile a really simple test program (It consists of empty setup() and loop() function). However, I am not able to get it to build properly (neither via VSCode or from CLI). Here’s an example output from the CLI so I can see what’s happening (I included the -j 1 because otherwise I get several similar “not found” warnings):

c:\Users\xyz\src\testprog>pio run -v -j 1
Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR 2.2.0 > Arduino Nano ATmega328
DEBUG: Current (simavr) On-board (simavr)
 - framework-arduino-avr 5.0.0
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 8 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
avr-g++ -o .pio\build\nanoatmega328\src\main.cpp.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p -DPLATFORMIO=40304 -DARDUINO_AVR_NANO -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=10808 -Iinclude -Isrc -IC:\Users\xyz\.platformio\packages\framework-arduino-avr\cores\arduino -IC:\Users\xyz\.platformio\packages\framework-arduino-avr\variants\eightanaloginputs src\main.cpp
avr-g++: error: src\main.cpp: No such file or directory
avr-g++: fatal error: no input files
compilation terminated.
*** [.pio\build\nanoatmega328\src\main.cpp.o] Error 1

But if I try to compile it manually, it works:

c:\Users\xyz\src\testprog>avr-g++ -o .pio\build\nanoatmega328\src\main.cpp.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p -DPLATFORMIO=40304 -DARDUINO_AVR_NANO -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=10808 -Iinclude -Isrc -IC:\Users\xyz\.platformio\packages\framework-arduino-avr\cores\arduino -IC:\Users\xyz\.platformio\packages\framework-arduino-avr\variants\eightanaloginputs src\main.cpp

The avr-g++ command in the latter example is the correct one.

The pio.exe command seems to work for everything else. It can download libraries and frameworks, so I don’t think it is an issue of antivirus blocking process spawning. I am unable to test this anyway because this is on my work laptop, but I would expect some “access denied” error if that was the case, or at least that the AV wrote something in its logs.

Does anyone have any idea what’s going on here?


Can you post your platformio.ini file from the project’s folder please? Thanks. There might be something there, maybe, perhaps!

In your command session, you are located in c:\Users\xyz\src\testprog – can you see the src/main.cpp file from there? Is there a platformio.ini file there too? If not, you need to be in the folder where the platformio.ini file is to be found, to run a compilation.

This line in your output:

is saying "find the file src/main.cpp, relative to where I am located, and compile it to an object file, then put it into .pio\build\nanoatmega328\src\main.cpp.o – also relative to where I am now.

Can you actually see the source file – src/main.cpp from within c:\Users\xyz\src\testprog?


Hi, and thanks for trying to help.

Yes, the main.cpp file exists under c:\Users\xyz\src\testprog\src\. And the avr-g++ command does produce a main.cpp.o file under .pio\build\nanoatmega328\src as long as I run the command manually. It is only when pio.exe tries to run the excact same command that it fails. I run all commands from the project’s “root” directory (c:\Users\xyz\src\testprog).

This is my c:\Users\xyz\src\testprog\platformio.ini file:

; PlatformIO Project Configuration File
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

platform = atmelavr
board = nanoatmega328
framework = arduino

This is the only platformio.ini file I have. I tried to copy it together with the main.cpp file (just so I can say that I’ve tried it :slight_smile:), but that didn’t help.

It’s not a %PATH% thing I wonder? The Windows instructions seem simple enough (I’m on Linux) however, they do say that:

If you follow that link, you find this:

I wonder if that’s the problem? I have no problems on Linux getting code to compile from the command line, or from VSCode - but I see that I have the PlatformIO stuff on my $PATH.


Is that path in a OneDrive cloud folder? That usually kills PIO. Also you should try and deactivate antivirus just to be sure.

It’s not a %PATH% thing I wonder? The Windows instructions seem simple enough (I’m on Linux) however, they do say that:

Sadly, it is not that simple :slight_smile:, but thanks anyway.

Is that path in a OneDrive cloud folder? That usually kills PIO. Also you should try and deactivate antivirus just to be sure.

It is not on OneDrive, nor any other cloud drive.

Unfortunately I cannot deactivate AV, because this is on a company laptop and that option is blocked.

Apologies for the question, but did you follow all the instructions at Redirecting... to install PlatformIO?

Just to be 100% certain.


Apologies for the question, but did you follow all the instructions at https://docs.platformio.org/en/latest/core/installation.html to install PlatformIO?

No need to apologize :slight_smile: I really appreciate the effort you’re putting into trying to help me.

And actually no, I didn’t follow all those instructions because I installed PIO from VSCode which I assume will perform all those steps for me. I only used the CLI to troubleshoot because it easier to find out what’s wrong when I can run the actual commands myself. However, the failed build result is the same both from VSCode and CLI.

But since you pointed them out, I tried to execute all the installation steps that seemed relevant, such as removing all Python installations (I had both 2.7 and 3.8) and reinstalling 3.8, installing virtualenv and enabling the development version of PIO. Nothing helped, though. I’m still stuck with that “src\main.cpp: No such file or directory” error, which I just don’t understand because I know that the file exists! :stuck_out_tongue:

Can you execute other python programs? I’m wondering if your company Antivirus is getting in the way?


Yes, Python works just fine on it’s own. I am curios, though, about the python.exe (and associated files) located in the .platformio/penv/scripts directory. It seems like PIO insists on using those instead of the global Python installation, because if I temporary remove them PIO fails with the error “unable to create process”.

Not that it think it really matters, because they seem to work just as well as the global installation when I try to run Python scripts with them.

That’s interesting. Especially as the pre-requisites for PlatformIO requires Python to be installed. I’ll have to look at what’s in my Linux equivalent directory and see what’s what.

Maybe your other Python stuff runs ok because it’s running from the “official” installation folder, but maybe the AV system is configured to not run executables from .platformio/penv/scripts?

Interestingly enough, on my last contract, where I had Windows 10, I couldn’t get PlatformIO to run either. The reason being it was outside the “sandbox” of locations permitted to run executables.

Just a thought.


I had a look on my Linux system, In .platformio/penv/bin I have python, python3.6 and python3.

Python3 is the actual python 3.6.9 interpreter, the other two are symbolic links to this file. If I execute python3 I get the usual output:

norman@Hubble:~/.platformio/penv/bin$ ./python3
Python 3.6.9 (default, Jul 17 2020, 12:50:27) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

However, if I rename any of those files (or move them elsewhere) I can still compile PlatformIO code. Interesting that Windows 10 doesn’t allow that, but Linux does. I’m not convinced that, on Linux at least, PlatformIO is using those installed files.

I’m sorry to say that I’m at a bit of a loss as to why your systems isn’t working. Sorry. :frowning: