PIO Unit Testing Not working in VSCode

I have configured a testing environment in my .ini file, and when I attempt to test, I am getting some sort of linker error. Here is my testing env:

[env:Testing]
platform = native

The error I get when trying to test main in the testing environment:

Processing Test1 in Testing environment

Building…
*** [.pio\build\Testing\test\Test1\main.o] Error 1
*** [.pio\build\Testing\test\output_export.o] Error 1
*** [.pio\build\Testing\UnityTestLib\unity.o] Error 1
================================================= [FAILED] Took 1.68 seconds =================================================

main.cpp file:

#include <unity.h>

void testOne(void)
{
    TEST_ASSERT_EQUAL_UINT8(7, 7);
}

int main(void) 
{
    UNITY_BEGIN();
    RUN_TEST(testOne);
    UNITY_END();
    return 0;
}

Any help would be appreciated.

I can reproduce the same error. Even though I have g++ and gcc installed and available in the PATH of a cmd.exe shell, PIO can’t find it. It also doesn’t make a difference if you use a .c or a .cpp file. This has also been reported in g++ not found · Issue #1 · platformio/platform-native · GitHub but with no resolution. @ivankravets, could you have a look at it?

Full log

Mkdir("C:\Users\Maxi\Documents\stackoverflow_testing\.pio\build\Testing")
PACKAGES: 
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
gcc -o .pio\build\Testing\src\main.o -c -DPLATFORMIO=40100 -Iinclude -Isrc src\main.c
The command "gcc" is either mistyped or could not be found.
*** [.pio\build\Testing\src\main.o] Error 1
 [FAILED] Took 1.07 seconds

@valeros please help

Just thought I’d mention I get the same also on Windows, when either running a Test task like the OP, or just doing a normal build. Linux is just fine. Windows fails with both cpp and c code.

Output
Linux
-----

> Executing task: platformio run <

Processing Testing (platform: native)
-----------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
PACKAGES: 
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Compiling .pio/build/Testing/src/main.o
Linking .pio/build/Testing/program
================================================ [SUCCESS] Took 0.69 seconds ================================================

> Executing task: platformio test <

Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

Processing * in Testing environment
-----------------------------------------------------------------------------------------------------------------------------
Building...
Testing...
test/main.cpp:11:testOne        [PASSED]

-----------------------
1 Tests 0 Failures 0 Ignored
OK
================================================ [PASSED] Took 0.96 seconds ================================================

Test    Environment    Status    Duration
------  -------------  --------  ------------
*       Testing        PASSED    00:00:00.958
================================================ 1 succeeded in 00:00:00.958 ================================================


Windows
-------

> Executing task: C:\Users\Peter\.platformio\penv\Scripts\platformio.exe run <

Processing Testing (platform: native)
---------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
PACKAGES:
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...    
No dependencies
Compiling .pio\build\Testing\src\main.o
'g++' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\Testing\src\main.o] Error 1
========================================= [FAILED] Took 8.12 seconds =========================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

> Executing task: C:\Users\Peter\.platformio\penv\Scripts\platformio.exe run <

Processing Testing (platform: native)
--------------------------------------------------------------------------------------------------------------- 
Verbose mode can be enabled via `-v, --verbose` option
Mkdir("e:\Projects\PlatformIO\native\unit_test_native\.pio\build\Testing")
PACKAGES: 
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Compiling .pio\build\Testing\src\main.o
'gcc' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\Testing\src\main.o] Error 1
========================================= [FAILED] Took 5.82 seconds =========================================
The terminal process terminated with exit code: 1


> Executing task: C:\Users\Peter\.platformio\penv\Scripts\platformio.exe test <

Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

Processing * in Testing environment
---------------------------------------------------------------------------------------------------------------
Building...
'g++' is not recognized as an internal or external command,
operable program or batch file.
'g++' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\Testing\test\main.o] Error 1
*** [.pio\build\Testing\test\output_export.o] Error 1
'gcc' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\Testing\UnityTestLib\unity.o] Error 1
========================================= [FAILED] Took 5.52 seconds =========================================

Test    Environment    Status    Duration
------  -------------  --------  ------------
*       Testing        FAILED    00:00:05.524
==================================== 1 failed, 0 succeeded in 00:00:05.524 ====================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

> Executing task: C:\Users\Peter\.platformio\penv\Scripts\platformio.exe test <

Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

Processing * in Testing environment
---------------------------------------------------------------------------------------------------------------
Building...
'g++' is not recognized as an internal or external command,
operable program or batch file.
'g++' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\Testing\test\main.o] Error 1
*** [.pio\build\Testing\test\output_export.o] Error 1
'gcc' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\Testing\UnityTestLib\unity.o] Error 1
========================================= [FAILED] Took 5.52 seconds =========================================

Test    Environment    Status    Duration
------  -------------  --------  ------------
*       Testing        FAILED    00:00:05.515
==================================== 1 failed, 0 succeeded in 00:00:05.515 ==================================== 
The terminal process terminated with exit code: 1

@pfeerick @maxgerhardt @db97 What version of gcc is installed in your system? Just tried with gcc 8.2.0 from MinGW and works fine:

Building...
Testing...
test\main.cpp:11:testOne        [PASSED]

-----------------------
1 Tests 0 Failures 0 Ignored
OK

Er… none? :blush:

I just re-read the docs, and the penny dropped… Native… and…

This platform uses built-in toolchains […] from particular OS where it will be run.

… i.e. when using native, PlatformIO does not supply the toolchain?

I think that documentation could be improved a bit… especially the rather pointless link to the PIO registry page for more information… which will pretty much point you back to the documentation page… rinse… repeat… :laughing:

After installing the gcc toolchain via the MinGW Install Manager, C:\MinGW\bin to my path, and restarting VSCode, it works! :slight_smile: edit: making that GCC-8.2.0-5.

Then again… perhaps platform = windows_x86 is what was wanted here? As that would have supplied the toolchain… and I see it seems it allows windows development on linux as well (I was going to say that was a bit crazy, but at least that means linux can be used for CI? :smile: :man_shrugging: )

7.2.0 from MinGW, compiler is in the PATH of the system, on Windows x64.

C:\Users\Maxi>g++ --version
g++ (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


C:\Users\Maxi>gcc --version
gcc (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


C:\Users\Maxi>which gcc
C:\Program Files (x86)\mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin\gcc.EXE

It shouldn’t depend on the compiler version should it? The error comes from not even finding gcc. It seems like it gets thrown out of the path somehow?

I have gcc 8.1.0.

PS C:\Users\danie> g++ --version
g++.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

PS C:\Users\danie> gcc --version
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

It doesn’t look to be dependent on the version of gcc installed, as @maxgerhardt is having the same problem with a different version