Thread: Make and GCC

  1. #1
    Registered User
    Join Date
    Feb 2022
    Posts
    1

    Question Make and GCC

    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?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,110
    Quote Originally Posted by ac427 View Post
    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?
    Yes!

    hello.c
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       printf("Hello World!\n");
       return 0;
    }
    Code:
    gcc -Wall -Wextra -Wpedantic -o hello  hello.c
    More options could be added.

    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.

  4. #4
    Registered User
    Join Date
    Feb 2022
    Posts
    45
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I make a constructor make code fail?
    By MutantJohn in forum C++ Programming
    Replies: 29
    Last Post: 08-31-2013, 06:59 PM
  2. Replies: 2
    Last Post: 04-27-2011, 04:14 PM
  3. Establishing 'make clean' with GNU make
    By Jesdisciple in forum C Programming
    Replies: 9
    Last Post: 04-11-2009, 09:10 AM
  4. How would I make a c++ prgoram make a .exe file?
    By Rune Hunter in forum C++ Programming
    Replies: 9
    Last Post: 12-26-2004, 05:56 PM
  5. Replies: 6
    Last Post: 04-20-2002, 06:35 PM

Tags for this Thread