I use coderunner installed in vscode to run my c++ code, but it just can't run in c++11 style so it always appears c++11 errors and warnings, how can i do to make it available to c++ 11 ?
For enabling C++11 on coderunner(vscode) please check if the setting has it enabled.
Go to
Settings > User Settings
In here, search for
Run Code Configuration:
In the menu find: "code-runner.executorMap"
Then edit the setting by adding it to User Setting as below for C++11 support:
"cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
Hope this helps !
For more help check this
Related
I wrote some C++ code in Windows. When I run make fileName from the Visual Studio Code terminal I see the command that make runs is g++ fileName.cpp -o fileName.
I then compile the same file in macOS Catalina using the same command make fileName and the command that make runs is c++ fileName.cpp -o fileName. I have run make -p -f /dev/null and saw that the CXX variable is set to c++ which is an alias to clang.
I would like make to use g++ on macOS as it does on windows.
I have seen posts mentioning you can change the implicit variables but haven't figured out how to do it. I already changed the default compiler in VS Code from usr/bin/clang to usr/bin/gcc and also tried with usr/bin/g++ but the command doesn't change to g++ fileName.cpp -o fileName as desired.
I have also tried running CXX=g++, and CXX='/usr/bin/g++ in the terminal but that didn't work.
Is there a way to do it? I would like to not have to create a makefile in my directory and instead just change the implicit rule.
I want to use c++11/14 features like range-based loops, but get a warning while doing g++ program.cpp. If done with compiler flag g++ -std=c++11 program.cpp the warning goes away. Is there a way to use c++11/14 by default on the g++ command (i.e without passing compiler flag every time).
Please explain to someone with limited knowledge of compilers and only need the c++11/14 features for competitive programming problems (even if it's a bad idea in general, maybe due to backward compatibility?)
Short Answer: Update your g++
According to g++ documentation
The default, if no C++ language dialect options are given, is -std=gnu++17.
You are probably using an older version of g++. You can check it using by running g++ --version in your terminal. If you are using Linux, you can also extract your default c++ standard from g++ manual with the command man g++ | col -b | grep -B 1 -e '-std.* default' in your terminal.
If you do not want to update your g++, you can also set a command alias by putting something like alias g+++='g++ -std=c++14' in your .bashrc
If you're using a gcc version > 4.9.3 use this command: g++ -std=c++14 program.cpp
If you're using an older version than that use g++ -std=c++1y program.cpp
Note: Consider adding the -Wall flag before program.cpp in your command to get warnings, they help you way more than you'd think!
Tip: If you're a starting developer and don't want too steep of a learning curve, try using an IDE before going full command-line.
EDIT: If you want a command to be "the default" you can add something like alias mycc='g++ -std=c++14 -Wall' in your .bashrc or .bash_profile file (see this link), then you'll be able to use mycc program.cpp
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm using Visual Studio Code to compile C++ programs and it works for most C++ programs as it compiles it using g++ command. However, I am facing difficulty in compiling c++11 programs using it.
When I try compiling C++11 programs, the compiler command g++ tries to compile it using default C++98 Standard and this results in errors.
I am aware that using g++ -std=c++11, we can compile C++11 programs using g++ and it works fine when I use it in my cmd as:
g++ -std=c++11 some_program.cpp
I wish I could tweak some setting in Visual Studio Code and change the compiler command from g++ to g++ -std=c++11 so that I could compile programs by just hitting the run code button. However, I'm not able to find one. Please help me out if there are alternate ways to get my program compiled.
Currently, I'm getting errors as:
some_program.cpp: In function 'int main()':
some_program.cpp:12:33: error: in C++98 'A' must be initialized by constructor, not by '{...}'
vector A = { 11,2,3,14 };
The snippets are correct and have been tested with online compilers using C++11. Here, it is trying to compile using C++98 as seen in the error.
Go to Settings > User Settings
In here, search for Run Code Configuration:
Under this menu, find:
"code-runner.executorMap"
Edit this Setting by adding it to User Setting as below for C++11 support:
"code-runner.executorMap":{
"cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},
OR
Edit this Setting by adding it to User Setting as below for C++17 support:
"code-runner.executorMap":{
"cpp": "cd $dir && g++ -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},
Hope this helps !
So I'm following the tutorials on this page:
http://www.cplusplus.com/doc/tutorial/control/
But I'm having trouble doing a range/based for loop. I found this page:
GNU GCC compiler updatingThe answer there says I should open "Project" and "Properties". But when I try that, the "Properties" option is grayed out with no explanation:
http://imageshack.com/a/img571/4371/xd1x.png
So.. how can I activate range/based for loops?
Pass -std=c++11 flag to the compiler. Certainly GCC should be fresh enough (>=4.7) to support all these modern standards. For CodeBlocks 13.12: Settings -> Compiler -> Tab "Compiler Flags" -> Option "Have g++ follow the C++11 ISO C++ [-std=c++11]"
The above given solution of using -std=c++11 didn't work for me.
This is the target and version detail of my compiler.
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
Target: x86_64-linux-gnu
When I tried, this is what happened.
$ g++ -std=c++11 program.cpp
cc1plus: error: unrecognized command line option ‘-std=c++11’
This solved the problem for me.
$ g++ -std=c++0x program.cpp
In Dev-Cpp 5.11 Simply you can click on Tools>Compiler Options>Settings>Code Generation>(and in last option)Language standard(-std) select from dropdown (ISO C++ 11).
If you faced this error in Code::Blocks, this might help you -
Click on Settings -> Compiler -> Compiler Settings -> Compiler Flags
Under the "General" section, check [✓] the box beside :
Have g++ follow the C++11 ISO C++ language standard [-std=c++11]
Both of these:
g++ -std=c++11 -o test_executable test_source.cpp
g++ -std=c++0x -o program program.cpp
worked for me.
Only thing to do after compiling is to execute the test_executable (in the first case) as ./test_executables or program (in the second case) as ./program.
Using the above solution
g++ -std=c++0x program.cpp
works. However, the command needs to be modified slightly in order to run the program with the common command:
./program
I used
g++ -std=c++0x -o program program.cpp
and all worked perfectly.
If you are using QT5.5, you can achieve it by adding following lines in your .pro file.
CONFIG += c++11
The best solution is doing this, in Dev C++:
Go to the "Tools" Option
Select "Compiler Options"
Click "Settings"
Click "Code Generation"
Go to "Choose Language" and select "ISO C++11"
Then your problem is resolved.
in first time, if you have Dev-C++
C:\Program Files (x86)\Dev-Cpp\MinGW64\bin, you must add this route to the path
then use the next command in cmd.
g++ -std=c++11 -o outprogram code_source.cpp
this command in your project directory.
I'm currently running ubuntu 13.10 with codeblocks and when I try to build it comes up with this message:
g++ -c /home/rhys/Documents/Progamming/c++/Class_private/main.cpp -o /home/rhys/Documents/Progamming/c++/Class_private/main.o
/bin/sh: 0: Can't open g++ -c /home/rhys/Documents/Progamming/c++/Class_private/main.cpp -o /home/rhys/Documents/Progamming /c++/Class_private/main.o
Process terminated with status 127 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)
It used to work fine but it does not work now, I have downloaded the build-essential, then the gcc complier which it is set to in the settings.
Can anyone help??
check "Settings -> Environment -> General settings -> Shell to run commands in:" and make sure it says "/bin/sh -c" you must have the -c argument. Either this or it could a file path problem with the compiler or source files themselves.
I think you must set the access for your files and/or your whole working directory. So go there, and change permission with chmod:
cd /home/rhys/Documents/Progamming/c++/Class_private/
chmod 755 *
If this not works maybe you should check if g++ is accessible. Run:
g++ --version
See if it prints the information or another error.
Another solution could be to open Code::Blocks as a superuser and then try again as you normally did.