HELP IN UPDATING TO C++14 Standard!!!

Hi! I recently tried to update my Code::Blocks compiler to the C++14 standard. I was following this video tutorial:
https://www.youtube.com/watch?v=IJeqADYg4l0

So, I went to the website and downloaded the latest installer, i set it up and then I went to my environment variables to change the PATH variable. Once I did that, I went to Code::Blocks and then went to Settings> Compiler and then created a copy of the GNU GCC Compiler. I went to toolchain executables changed the directory to C:\MinGW\bin and saved. However, when I went to the compiler settings, I did not see an option for C++14. I wanted to test if C++14 was on the compiler and tried using the features

1
2
3
4
5
6
7
8
9
10
11
12
13
  #include <iostream>

using namespace std;
auto div(int a, int b)
{
    return a/b;
}
int main()
{
    auto abc = make_unique<int>();
    div(6,2);
    return 0;
}


The div() function works but the make_unique<int>(); gave me an error saying that says that make_unique was not defined in the std namespace. How can I fix this?

EDIT: Ignore everything I previously said, the make_unique function is defined in <memory>


I went to Settings -> Compiler -> Other Options and added -std=c++14 (also try -std=c++1y) there.
div and make_unique work for me now.

Except the name "div" was apparently already used by some internal thing in the compiler...
div_t __cdecl div(int _Numerator,int _Denominator);
which is weird since I thought a name like "div" would be perfectly legal. I changed the name to divx().
Last edited on
http://en.cppreference.com/w/cpp/numeric/math/div

This is why using namespace std; is bad.
d'oy I should've seen that when I ran his code.

Edit:
Actually I still get a problem without that, it originates from the <memory> header, which for some reason includes stdlib.h somewhere down its implementation, which of course is not protected by std namespace.

(Note that this isn't the OP's problem, just something little i noticed)

1
2
3
4
5
6
7
8
9
auto div(int a, int b)
{
    return a/b;
}

int main()
{
    div(6,2);
}

Compiles fine.
But if I add #include <memory> before div, you get ambiguous errors.
Perhaps it's just an oversight on MinGW's implementation.
Last edited on
Thanks for the replies, I will try it when I get to my PC. Also I have a question: why does enable c++14 not show up in the drop down menu on the compiler settings? And also does the latest version of MinGW support all c++14 features?
why does enable c++14 not show up in the drop down menu on the compiler settings?
Because your IDE was not updated to support C++14 switch.
does the latest version of MinGW support all c++14 features?
It supports almost all language features. And AFAIK it technically support almost all library features, but some features are underimplemented in Windows port (for example anything related to locales)
https://gcc.gnu.org/projects/cxx1y.html
https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2014
@Ganado I tried what you said and it didn't work. I'm still getting two errors even after trying to add -std=c++14 or -std=c++1y and including <memory>. Why does it still not work? do I have the right version of the compiler? And Also, I'm not sure if changing the PATH in environmental variables was necessary.
Last edited on
do I have the right version of the compiler?
Which compiler version do you have? MinGW bundled with C::B by default does not support C++14. You have to install one manually.
But if I add #include <memory> before div, you get ambiguous errors.
Perhaps it's just an oversight on MinGW's implementation.
Standard headers are allowed to include other standard headers.

That is why namespaces exist: to eliminate name clashes. move your div function in some namespace
I have the version on sourceforge that I installed with a installer program. I clicked on the link at the top that says "Looking for the latest version? Download mingw-get-setup.exe (86.5 kB)"

http://sourceforge.net/projects/mingw/files/

I am mostly concerned about make_unique and make_shared not working. I don't know if it had anything to do with me changing the PATH environment variable.
(Not an expert on this kind of stuff)
Last edited on
So, which version is it? Go to the directory where MinGW/bin is, launch command window and do g++ -v. You will have huge list of info and in the end you will see something like
Thread model: posix
gcc version 4.9.1 (x86_64-posix-seh-rev1, Built by MinGW-W64 project)


If you have version 4.8, then it is too old.
Gah, I feel so stupid! I have version 4.8.1. I have no clue why this happened because I clicked install the latest version.

Can someone tell me how to delete the installed version of MinGW? And can you also provide a link to the 4.9 version? Thank you
how to delete the installed version of MinGW?
Usually it is enough to delete directory containing MinGW. However do you really need to do that? different compiler versions can coexist easily.

And can you also provide a link to the 4.9 version?
Make your pick:
http://nuwen.net/mingw.html
http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.1/

You will need to create your own compiler toolchain in C::B configuration and correctly write all paths. Look at the existing MinGW one to see what you should do.
So do I make a copy of the GNU GCC compiler and edit the toolchain executables from there once I've installed it?
I used nuwen.net's 4.9 on Windows, it was an easy unpackaging install iirc, explained on their site.

Here's how I have mine set up. I have the version of MinGW installed in C:/MinGW
http://i.cubeupload.com/66zT2i.png

Edit: Actually my "Make Program" should be should be mingw32-make.exe, I forgot why I changed it to that, something to do with msys I think, but that shouldn't affect the compiler itself.
Last edited on
I usually symlink make.exe and mingw32-make.exe so that they both exist. CMake will not detect MinGW without the latter.
So I create a copy compiler and add the new compiler's path from the toolchain executives?
Yes.
Thanks to everyone that helped me on this thread! I appreciate it! The file is safe and free of viruses, correct?

EDIT: Got it working. Thanks!
Last edited on
Topic archived. No new replies allowed.