I am just starting out into learning C.
Is there a specific reason why both make and GCC are used when compiling?
Could i not just compile the C contained in a txt using GCC and not use make?
I am just starting out into learning C.
Is there a specific reason why both make and GCC are used when compiling?
Could i not just compile the C contained in a txt using GCC and not use make?
Sure, there's nothing stopping you compiling single source files just by typing
gcc -o prog prog.c
You can even do it for multiple files, at the expense of wasting a bit of machine time.
gcc -o prog prog.c file.c other.c something.c
make really becomes useful when you have ~10+ source files, because it will only recompile those files which need compiling.
It's there when you need it, but for the moment it's not something to stress over.
The useful order is
editor
compiler
debugger - gdb
git / svn / mercurial / ...
make / cmake
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Yes!
hello.c
Code:#include <stdio.h> int main(void) { printf("Hello World!\n"); return 0; }More options could be added.Code:gcc -Wall -Wextra -Wpedantic -o hello hello.c
make is used to aid in compiling programs with multiple .c and/or .h files, but for simple programs, and when learning C, make is not needed.
There is no requirement to use make, no. You can call gcc at the shell prompt, or put the invocation in a shell script; you can even use one of several alternatives to make such as CMake or SCons, though most of those are more complicated than Make rather than less, being meant primarily for particularly complex build processes.
For a simple program being compiled from the shell prompt, using gcc manually should be perfectly fine.
However, some editors and IDEs assume the use of Make, or some Make-like project file specific to the IDE. You may be able to coax them to bypass this, but I could guarantee it.
Also, a Makefile is a lot more than just a shell script; it allows very fine-tuned control over complex build processes, and automates a number of things such as checking to see whether a given source file has been touched since the last time the sub-build was compiled. For any non-trivial compilation, a build tool or project manager of some sort is the best way to avoid making mistakes through typos and the like.
Last edited by Schol-R-LEA-2; 02-23-2022 at 09:49 AM.