tutorial request problem

Oct 13, 2020 at 9:55pm
The tutorial I'm using currently was suggested by somebody in this forum. Seem to keep up with the updating but the problem is.

https://www.learncpp.com/cpp-tutorial/configuring-your-compiler-choosing-a-language-standard/

This is current page I'm on. Asked me to test to see if my current compiler has 2017. So far what I did

Downloaded codeblock from https://wiki.codeblocks.org/downloads/26

I assume this is latest one the one with codeblocks-20.03mingw-setup.exe

I followed the direction tutorial, but only thing I cant see is

g++ follow the C++1z (aka C++17) ISO C++ language standard [-std=c++1z] This one is missing from the list when I check the compiler setting.

to be exact what I have on my global compiler settings

Selected compiler

GNU GCC Compiler

Only one that has checked on compiler flags is Have g++ follow the C++11 ISO C++ language standrad [-std=c++

toolchain executables has

gcc.exe
g++.exe
g++.exe
ar.exe
GDB/CDB debugger:Default
windres.exe
mingw32-make.exe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#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;
}


the error are

line 3 fatal error: string_view: no such file or directory


Last edited on Oct 13, 2020 at 10:05pm
Oct 13, 2020 at 11:58pm
If you installed Code::Blocks 2003 with MinGW included the compiler flag for C++17 is properly listed in the projects build options as [-std=c++17] instead of [-std=c++1z].

I didn't change any configurations, I did a default install (other than selecting a different install location).

The selected compiler should be "GNU GCC compiler."

You've found one part of Learn C++ that isn't as up-to-date as possible.

FYI, the MinGW version bundled with C::B 2003 is not the most recent, so C++20/2a support is not part of the bundle.
Oct 14, 2020 at 12:04am
Your sample code works with C::B on my development machine when using -std=c++17.

Works as well in Visual Studio 2019 with the C++17 language standard.

<string_view> is a C++17 library, so compiling as C++11 will bomb out.
Oct 14, 2020 at 12:32am
Alright, do I ignore that step and move on?

Or does anybody have an accurate link that has c++ 17 updated in the MinGW for Code::block?

In the setting compiler I checked the box that has -std=c++17 tho its not g++ its gcc. The result is same as before.
Oct 14, 2020 at 1:24am
gcc is the C compiler, not the C++ compiler. You should use g++ with C++ files so the standard C++ library files are properly linked for your C++ app.
https://www.geeksforgeeks.org/difference-between-gcc-and-g/

The current C::B download: http://www.codeblocks.org/downloads/26

If unsure, please use codeblocks-20.03mingw-setup.exe!

IF you download C::B and have a previous install I suggest you uninstall the previous install first. As well as removing any left-over files and directories. That makes sure all the proper default settings are set properly when installing the latest C::B version.
Oct 14, 2020 at 2:02am
Alright, do I ignore that step and move on?

No, just mentally make the change from -std=c++1z to -std=c++17 so you are finding the proper setting(s) to change as needed.

Going over my download records from May 2020 I downloaded and installed the "codeblocks-20.03mingw-setup.exe" for Windows.
Oct 14, 2020 at 3:47pm
I finally got right one, I uninstall everything from my computer relate to Code::Block, even the register. Reinstall but used different source this time. This time the have g++ follow the C++17 ISO C++ language standard [-std=c++17] is there in the list.

two day of fighting with error, Finally got it to working. Thank you all for the help.
Oct 14, 2020 at 4:44pm
I am glad you got things to work, sometimes the tools we use can be cranky. It doesn't help someone new to programming.

I personally wouldn't have bothered with mucking around with the registry, it can be all too easy to mess up the editing and turn a functioning computer into a large unbootable door stop.

It looks like you have a Windows PC. If you have the space you might consider also installing Visual Studio. There is a Community edition that is free. Fair warning, VS does take a lot of HD space to install. On my development PC about 20GBs.

Having different compilers can help creating "agnostic" as possible C++ code. I use both C::B and VS to test drive my code from time to time. Sometimes what works with one IDE/compiler errors out with another. Some tweaks and now the code works for both.
Oct 16, 2020 at 3:43pm
Thank for the suggested. This computer is customized for gaming. Should be able to download any size.
Oct 16, 2020 at 3:59pm
IF you do install VS you need to do a custom install. The C++ packages are not installed by default.

There are some packages that VS default installs that you might not want cluttering up your HD. F# is one IIRC. Doing a custom install gets what you want.

You can download the entire install package so installing can be done offline (Use the command line to create a local cache):
https://docs.microsoft.com/en-us/visualstudio/install/create-an-offline-installation-of-visual-studio?view=vs-2019
Last edited on Oct 16, 2020 at 3:59pm
Topic archived. No new replies allowed.