PlatformIO Community

Problem with compiler/c++ version when building

I’m working on a PIO project using c++17 as standard and the mingw-w64 gcc compiler. When building I get lots of errors like
‘__sv_check’ is not a member of ‘std’
‘__c_locale’ was not declared in this scope
For me it seems like the gcc compiler and the c++ version aren’t working together well because most of the errors come from blocks in the header files that ar in a #if __cplusplus >= 201703L condition.
I made sure to include all the necessary header files and everything but I cannot get it to work.
Does anyone know how to fix this or had issues of this kind before?

What’s the gcc --version that is being used here?

What’s the platformio.ini and minimal code that reproduces the issue?

gcc version is

gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.

the improtant platformio.ini code is

[env:native]  
platform = native  
build_flags =  
    ${common.build_flags}  
    -std=c++17  
    -DTARGET_NATIVE  
lib_ignore =  
    HALTarget  

and one of the examples where it gives me an error:

#ifndef _BASIC_STRING_H  
#define _BASIC_STRING_H 1  

#pragma GCC system_header  

#include <ext/atomicity.h>  
#include <ext/alloc_traits.h>  
#include <debug/debug.h>  

#if __cplusplus >= 201103L  
#include <initializer_list>  
#endif  

#if __cplusplus >= 201703L  
# include <string_view>  
#endif  

// some code...  

#if __cplusplus >= 201703L   

      //some other code...  

      template<typename _Tp>  
        _If_sv<_Tp, basic_string&>  
      append(const _Tp& __svt, size_type __pos, size_type __n = npos)  
      {  
        __sv_type __sv = __svt;  
        return _M_append(__sv.data()  
            + std::__sv_check(__sv.size(), __pos, "basic_string::append"),  
            std::__sv_limit(__sv.size(), __pos, __n));  
      }  
#endif // C++17  

there it says that ‘__sv_check’ is not a member of ‘std’

What is a simple main.cpp with which the error occurs?

If I take a simple

[env:native]
platform = native
build_flags = -std=c++17
#include <string>
#include <iostream>

int main() {
   std::cout << "Hello, world!" << std::endl;
   return 0;
}

it works fine.

>pio run -v
Processing native (platform: native; build_flags: -std=c++17)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 1 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
g++ -o .pio\build\native\src\main.o -c -std=c++17 -DPLATFORMIO=50200 -Iinclude -Isrc src\main.cpp
g++ -o .pio\build\native\program.exe .pio\build\native\src\main.o -L.pio\build\native
========================================================================================== [SUCCESS] Took 1.31 seconds ==========================================================================================

C:\Users\Max\temp\native_c17>.pio\build\native\program.exe
Hello, world!

But I also have

g++ (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 10.2.0

from here.

Ok, so I researched a bit more and i think my problem is similar to the one in this thread. I will try the solution mentioned there, but thanks for your help :smiley:

Are you sure? I don’t see anything that related in there.

Can you post the whole project maybe if you still get errors?

Ok, so I finally figured out my problem(s). I reinstalled mingw and chose “seh” as exception handling option. I also had some linux header files in my includes that hat to be replaced.