问题
I have a main.cpp file in my C:\Documents folder. What is the command that I need to type in order to compile this program in C++11?
And also, is there a way to include options like -Wall, -Wextra, or -Werror, similar to how you can do so in Ubuntu?
回答1:
Assuming you have GCC:
- Go to the Start and type
command prompt. Once the option is displayed, make sure that you right click it, and run it as an administrator. You need admin rights, in order to run the.exefile that is generated after compilation. - Once
command prompt(cmd) opens, navigate to theDocumentsfolder, since that is where your Main.cpp file is. Then type:
g++ -std=c++11 -Wall Main.cpp -o Main.exeThis will create a file named
Main.exein yourDocumentsfolder. Since you have admin rights, you can simply run:Main.exe
Sample screen shot below:
You can find detailed options about compilation here.
来源:https://stackoverflow.com/questions/37371107/windows-10-compile-c-in-cmd