How to compile C program on command line using MinGW?

前端 未结 14 1098
天命终不由人
天命终不由人 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:46

    I had the same problem with .c files that contained functions (not main() of my program). For example, my header files were "fact.h" and "fact.c", and my main program was "main.c" so my commands were like this:

    E:\proj> gcc -c fact.c
    

    Now I had an object file of fact.c (fact.o). after that:

    E:\proj>gcc -o prog.exe fact.o main.c
    

    Then my program (prog.exe) was ready to use and worked properly. I think that -c after gcc was important, because it makes object files that can attach to make the program we need. Without using -c, gcc ties to find main in your program and when it doesn't find it, it gives you this error.

提交回复
热议问题