How to compile C program on command line using MinGW?

前端 未结 14 1101
天命终不由人
天命终不由人 2021-01-30 17:19

What command does one have to enter at the command line in Windows 7 to compile a basic C program?

Like I am literally wondering what you type in the command prompt, to

相关标签:
14条回答
  • 2021-01-30 17:53

    make as usual... Just make sure you have it in your path and correct Makefile

    0 讨论(0)
  • 2021-01-30 17:55

    In Windows 10, similar steps can be followed in other versions of windows.

    Right Click on "My Computer" select Properties, Goto Advanced System Settings -> Advanced -> Select "Environment Variables.." .

    Find "Path" select it and choose edit option -> Click on New and add "C:\MinGW\bin" (or the location of gcc.exe, if you have installed at some other location) -> Save and restart command prompt. Gcc should work.

    0 讨论(0)
  • 2021-01-30 17:56

    You can permanently include the directory of the MinGW file, by clicking on My Computer, Properties, Advanced system settings, Environment variables, then edit and paste your directory.

    0 讨论(0)
  • 2021-01-30 17:57

    It indicates it couldn't find gcc.exe.

    I have a path environment variable set to where MinGW is installed

    Maybe you haven't set the path correctly?

    echo %path%
    

    shows the path to gcc.exe? Otherwise, compilation is similar to Unix:

    gcc filename.c -o filename
    
    0 讨论(0)
  • 2021-01-30 17:58

    Instead of setting the %PATH% you may enter your msys shell. In standard msys and mingw installation gcc is in path, so you can run gcc or which gcc.

    I have a batch file sh.bat on my Windows 7, in %PATH%:

    C:\lang\msys\bin\sh.exe --login %*
    

    Whenever I want to use gcc I enter cmd, then sh, then gcc. I find it very convenient.

    When working with linux originated software avoid spaced directories like Program Files. Install them rather to Program_Files. The same regards to tools that you may want to run from msys environment.

    0 讨论(0)
  • 2021-01-30 18:03

    I once had this kind of problem installing MinGW to work in Windows, even after I added the right System PATH in my Environment Variables.

    After days of misery, I finally stumbled on a thread that recommended uninstalling the original MinGW compiler and deleting the C:\MinGW folder and installing TDM-GCC MinGW compiler which can be found here.

    You have options of choosing a 64/32-bit installer from the download page, and it creates the environment path variables for you too.

    0 讨论(0)
提交回复
热议问题