PlatformIO Community

G++ is not recognized

Hello

I’m walking through Unit Testing. Separated my test code into two division : embedded and native. as demonstrated in docs and examples.

Embedded-based test ran successfully, but I face now an issue when running a test in native environment : g++ isn’t recognized.

PS C:\Users\Hamza\Documents\PlatformIO\Projects\Testss> pio test -e native
Verbose mode can be enabled via `-v, --verbose` option
Collected 2 items

Processing test-native in native 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.
'g++' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\native\test\output_export.o] Error 1
*** [.pio\build\native\test\test-native\test.o] Error 1
*** [.pio\build\native\lib800\calculator\Calculator.o] Error 1
'gcc' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\native\UnityTestLib\unity.o] Error 1
============================================================= [FAILED] Took 4.08 seconds =============================================================

Test           Environment    Status    Duration
-------------  -------------  --------  ------------
test-embedded  nodemcuv2      IGNORED
test-embedded  native         IGNORED
test-native    nodemcuv2      IGNORED
test-native    native         FAILED    00:00:04.083
======================================================= 1 failed, 0 succeeded in 00:00:04.083 =======================================================

I’ve added MinGW/bin folder (that contains g++.exe) into PATH.

It’s now recognized at Windows cmd.
image

But still not recognized in VSCode / PIO.

Testing g++ commands in VSCode Terminal :

Tried running VSCode as Administrator. Didn’t work for me.

What I’ve missed ?

Did you restart VSCode after updateing your system path? AFAIK, it only gets loaded by the application (regardless of what application it is) when it starts, so any updates when it’s running won’t take.

Also, if you go into File -> Settings and search for ‘custom path’ you should find the platformio-ide custom path setting which could fix that up also. Not sure if you need to restart VSCode after altering that setting, or just close any active terminals.

Thanks @pfeerick for reply.

Yes I’ve restarted VSCode and still not recognized.

I’ve navigated to platform-ide custom path settings, I don’t know what to tweak over. I’ve the following :

{
    "C_Cpp.updateChannel": "Insiders",
    "extensions.ignoreRecommendations": false,
    "workbench.iconTheme": "material-icon-theme",
    "editor.fontFamily": "Fira Code, Monaco, 'Courier New', monospace",
    "editor.fontSize": 18,
    "workbench.colorTheme": "βui - One Dark",
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "window.zoomLevel": 0,
    "editor.tabCompletion": "on",
    "[cpp]": {
        "editor.defaultFormatter": "ms-vscode.cpptools"
    },
    "diffEditor.ignoreTrimWhitespace": false
}

Should I add something inside [cpp] key ?

It looks like the key for that setting is "platformio-ide.customPATH", so try adding that, and pointing it to the folder with your g++ executable, etc, and see if that makes any difference. Probably needs double \\ for escaping. should be able to go at the global level… not necessarily at the [cpp] level.

Unfortunately I still get the same error.

Added :

"platformio-ide.customPATH": "C:\\MinGW\\bin"

Where g++.exe in under that bin folder.

Tried g++ in Windows PowerShell, Which worked without any problem :

Known issue (https://github.com/platformio/platform-native/issues/1) needs guidence from @ivankravets

1 Like

Did you add C:\\MinGW\\bin to the system PATH environment variable in OS?

1 Like

Yes I’ve added that.

I only needed to add it to the user section of the environment variables. Changes to environment variables will also require any open terminals and/or VSCode to be restarted. It may even be necessary to restart the computer, if the WM_SETTINGCHANGE message that is broadcast when environment variables are updated is not being handled.

What happened to the other entries in your System path? There are usually a lot of entries by default, including your Windows and Windows/System32 directories.

To see if the path has updated, or is correct, in the powershell window, try running $env:path, and see if C:\MinGW\bin is in the list.

I’ve restarted my computer and nothing changed.

They present in my system’s path. just scrolling gets me there :

image

Now checking the output of command $env:path in VSCode PowerShell gives me a lot of entries but not C:\MinGW\bin.

Else: running in Windows PowerShell $env:path gives me only “C:\MinGW\bin”
image

As for feedback process : It’s fixed at the end :

The fix journey started by disabling all extensions for VSCode, Here after : it shows only g++ path (as shown in PowerShell above, and didn’t recognize PlatformIO.

So I Added PIO Script folder to Path.

Then It successfully run Test as native with g++.

Thanks for all guys helped to reach the point. (y)

1 Like