Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: tumanovalex on February 04, 2024, 12:01:12 am

Title: Error compiling program with the option C++20
Post by: tumanovalex on February 04, 2024, 12:01:12 am
Hello!
Installed codeblocks-20.03-32bit-mingw-32bit-setup.exe . In a simple program:
Code
#include <iostream>
#include <filesystem>
#include <map>
#include <string>

using namespace std;

namespace fs = filesystem;

int main()
{
  setlocale(LC_ALL, "Russian");
  map <string, unsigned int> map_ext;
  for (const fs::directory_entry& dir_entry : fs::recursive_directory_iterator("N:\\TestProgramExt\\"))
  {
    if (fs::is_regular_file(dir_entry))
    {
      string ext = fs::path(dir_entry).extension().string();
      ++map_ext[ext];
    }
  }
  for (auto&& [ext, num] : map_ext)
    std::cout << ext << "\t" << num << std::endl; 
  std::cin.get();
  return 0;
}
I get errors when installing compilation options (C++2020 standard):
Code
-------------- Build: Debug in cbCppStudy (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -std=gnu++20  -c N:\MyProgramming\cppStudy\cppStudy.cpp -o obj\Debug\cppStudy.o
mingw32-g++.exe  -o bin\Debug\cbCppStudy.exe obj\Debug\cppStudy.o   
mingw32-g++.exe: error: unrecognized command line option '-std=gnu++20'; did you mean '-std=gnu++2a'?
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 
-------------- Build: Debug in cbCppStudy (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -std=c++20  -c N:\MyProgramming\cppStudy\cppStudy.cpp -o obj\Debug\cppStudy.o
mingw32-g++.exe  -o bin\Debug\cbCppStudy.exe obj\Debug\cppStudy.o   
mingw32-g++.exe: error: unrecognized command line option '-std=c++20'; did you mean '-std=c++2a'?
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
This program compiles without errors in Visual Studio 2022, but I work more often in CodeBlocks.
Please help me solve the problem.
Title: Re: Error compiling program with the option C++20
Post by: Grit Clef on February 04, 2024, 06:32:43 am
What's Your GCC Version? That's not related to CodeBlocks, but Your compiler. GCC, 10 and higher, have an acceptable support for C++20.
Title: Re: Error compiling program with the option C++20
Post by: tumanovalex on February 04, 2024, 09:45:13 am
Thanks for the reply. The version of g++ 8.1 supplied in this distribution. Is it possible to make sure that the distribution includes the most modern version MinGW? In order not to look for the compiler in other places, but to use it immediately together with code blocks?
Title: Re: Error compiling program with the option C++20
Post by: tumanovalex on February 04, 2024, 10:12:51 am
Thank you very much for the answer, I found a modern compiler and everything worked out. My suggestion to include a modern compiler in the distribution is stupid, because compiler versions change very quickly.
Title: Re: Error compiling program with the option C++20
Post by: user2024 on February 09, 2024, 11:16:14 pm
My suggestion to include a modern compiler in the distribution is stupid, because compiler versions change very quickly.
I don't think it's that stupid. A compiler that is actual at the time of release wouldn't be asking too much.
Title: Re: Error compiling program with the option C++20
Post by: stahta01 on February 10, 2024, 12:59:07 am
My suggestion to include a modern compiler in the distribution is stupid, because compiler versions change very quickly.
I don't think it's that stupid. A compiler that is actual at the time of release wouldn't be asking too much.

From https://gcc.gnu.org/releases.html (https://gcc.gnu.org/releases.html)
gcc 8.5 was released on May 14, 2021
Therefore, I think the question is not really a good one. Edit: ?8.1? was the version packaged by the third party at the time CB was getting ready for release. And, for good reason the do not wish to change it after the CB goes into something like a feature freeze used by other projects.

Edit: But, I have always maintained that releasing an Compiler with CB was not worth the effort; but, the CB Dev Team has maintained it is needed by the schools that choose CB.

Tim S.