KDE neon 5.23, Code::Blocks 20.03 rev 11997, gcc 11.2.0. I installed Code::Blocks from Flathub
So, I'm trying to learn C++. The tutorial I'm using to learn it recommends using C++17 or C++20 to get the best experience on the site. The problem is that the two (yes, just two) C++ options I found in the compiler settings were for 1998.
I tried on a Windows 11 machine, and every option showed up as expected, such as "Have g++ follow the C++17 ISO C++ language standard [-std=c++17]" along with some slightly older versions (14, 11, etc.) which is what I was expecting to see on my Linux machine. But I don't see it.
The tutorial has some example code that you can compile to test C++17 compatibility:
#include <array>
#include <iostream>
#include <string_view>
#include <tuple>
#include <type_traits>
namespace a::b::c
{
inline constexpr std::string_view str{ "hello" };
}
template <class... T>
std::tuple<std::size_t, std::common_type_t<T...>> sum(T... args)
{
return { sizeof...(T), (args + ...) };
}
int main()
{
auto [iNumbers, iSum]{ sum(1, 2, 3) };
std::cout << a::b::c::str << ' ' << iNumbers << ' ' << iSum << '\n';
std::array arr{ 1, 2, 3 };
std::cout << std::size(arr) << '\n';
return 0;
}
I compiled this code and I got no errors. I also compiled some other code to see what C++ version I had, and it said C++17. This was the code:
#include <iostream>
int main() {
if (__cplusplus == 201703L) std::cout << "C++17\n";
else if (__cplusplus == 201402L) std::cout << "C++14\n";
else if (__cplusplus == 201103L) std::cout << "C++11\n";
else if (__cplusplus == 199711L) std::cout << "C++98\n";
else std::cout << "pre-standard C++\n";
}
If I can use C++17, why don't any new C++ versions show up in the compiler settings, and how do I fix it?
Also, please let me know if I should move this post to another category. I think this is a compiler issue, so maybe it should be put somewhere else.
If you're wondering why I installed Code::Blocks from Flathub instead of from my system's package manager or the website, it's because Code::Blocks doesn't look very good with a dark theme, and for some reason Flatpaks just don't want to respect the system theme, so this works for Code::Blocks, I guess.
MSys2 64 bit mingw
$ gcc --version
gcc.exe (Rev5, Built by MSYS2 project) 11.2.0
Copyright (C) 2021 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.
Tim S.
Thank you, Tim.
@logicalwillow, can you test these two commands in the Linux machine?
gcc -dumpversion
gcc -dumpfullversion
C::B 20.03 has the option for GCC "-std=c17".
If you want C++20 standard you have two options:
1) Download and use the nightly build as it includes the options included in 2) below.
2) Add either of the following in the "Other compiler options tab":
-std=c++20
-std=gnu++20
-std=c++2a
-std=gnu++2a
But before using these make sure you read the GNU GCC Standards support for the version of GCC you are using as they may not support all of the C++20 or even the C++17 standards depending on the version you are have.
If you want to use eh GNU C++23 standard then lookup the GNU GCC Stanards support for what the compiler option is and how compatible the version you have is.
Thanks, I'll run those and let you know what happened. I can't use any nightly builds because I couldn't find any for Linux. Just Windows. Do you know why almost no C++ options showed up in the compiler menu?
Thank you, Tim.
@logicalwillow, can you test these two commands in the Linux machine?
gcc -dumpversion
gcc -dumpfullversion
The gcc command doesn't exist, apparently. I also tried replacing "gcc" with "cpp":
$ cpp -dumpversion
9
$ cpp -dumpfullversion
9.3.0