News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Why don't any recent C++ versions appear in the compiler settings?

Started by logicalwillow, January 01, 2022, 04:58:14 AM

Previous topic - Next topic

logicalwillow

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.

AndrewCot

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.

Miguel Gimenez

Can anybody with gcc11 check if this command works on command line?
gcc -dumpversion

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

stahta01


$ gcc -dumpversion
11.2.0


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

stahta01

QuoteCode::Blocks from Flathub

6 months ago this was known to not work!

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

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Miguel Gimenez

Thank you, Tim.

@logicalwillow, can you test these two commands in the Linux machine?

gcc -dumpversion
gcc -dumpfullversion




Miguel Gimenez

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

Quote from: AndrewCot 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.

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?


Quote from: Miguel Gimenez on January 01, 2022, 11:34:46 AM
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

Miguel Gimenez

QuoteDo 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

Quote from: Miguel Gimenez on January 01, 2022, 08:06:37 PM
QuoteDo 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?

Miguel Gimenez

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.