Author Topic: Why don't any recent C++ versions appear in the compiler settings?  (Read 7509 times)

logicalwillow

  • Guest
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:
Code
#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:
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.

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #1 on: January 01, 2022, 06:47:17 am »
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.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #2 on: January 01, 2022, 11:04:06 am »
Can anybody with gcc11 check if this command works on command line?
Code
gcc -dumpversion

We rely on this command to show flags, and I know gcc devs wanted to remove it some time ago.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #3 on: January 01, 2022, 11:17:37 am »
Code
$ gcc -dumpversion
11.2.0

MSys2 64 bit mingw

Code
$ 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #4 on: January 01, 2022, 11:20:10 am »
Quote
Code::Blocks from Flathub

6 months ago this was known to not work!

Edit: Add link https://forums.codeblocks.org/index.php/topic,23943.msg163332.html#msg163332

Tim S.
« Last Edit: January 01, 2022, 11:53:30 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #5 on: January 01, 2022, 11:34:46 am »
Thank you, Tim.

@logicalwillow, can you test these two commands in the Linux machine?
Code
gcc -dumpversion
gcc -dumpfullversion



Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #6 on: January 01, 2022, 02:37:51 pm »
The problem with 20.03 and gcc11 is using grep to detect version, it worked well until gcc10 but not now. The current code uses proper version comparation.

In any case, the output of the commands above is still useful.

logicalwillow

  • Guest
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #7 on: January 01, 2022, 06:36:19 pm »
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?
Code
gcc -dumpversion
gcc -dumpfullversion



The gcc command doesn't exist, apparently. I also tried replacing "gcc" with "cpp":
Code
$ cpp -dumpversion
9
$ cpp -dumpfullversion
9.3.0
« Last Edit: January 01, 2022, 07:12:00 pm by logicalwillow »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #8 on: January 01, 2022, 08:06:37 pm »
Quote
Do you know why almost no C++ options showed up in the compiler menu?
The problem is described above, basically C::B 20.03 recognizes g++ v11 as g++ v1, so it hides the unsupported modes.

Cpp is the C preprocessor, try g++ instead.

logicalwillow

  • Guest
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #9 on: January 01, 2022, 08:13:27 pm »
Quote
Do you know why almost no C++ options showed up in the compiler menu?
The problem is described above, basically C::B 20.03 recognizes g++ v11 as g++ v1, so it hides the unsupported modes.

Cpp is the C preprocessor, try g++ instead.

The g++ command doesn't exist either. Also, if the items don't show up on Linux, why do they show up on Windows?

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #10 on: January 01, 2022, 08:32:06 pm »
Probably they do not appear because Flatpack has them jailed.

On Windows the nightlies are not affected, and possibly you are using a g++ version < 10.

logicalwillow

  • Guest
Re: Why don't any recent C++ versions appear in the compiler settings?
« Reply #11 on: January 01, 2022, 09:55:15 pm »
Thanks for the help!