Windows 10 - Compile C++ in cmd

天涯浪子 提交于 2019-12-24 01:42:09

问题


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:

  1. 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 .exe file that is generated after compilation.
  2. Once command prompt (cmd) opens, navigate to the Documents folder, since that is where your Main.cpp file is.
  3. Then type:

    g++ -std=c++11 -Wall Main.cpp -o Main.exe
    
  4. This will create a file named Main.exe in your Documents folder. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!