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>
usingnamespace 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().
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.
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?
@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.
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)"
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)
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)
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.
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.