0

I have installed make compiler for C, but it doesn't work. I have MinGW installed and installed mingw32-make and choco make, but neither of them works. They both output the same error when I try to compile a hello world C program called hello.c:

#include <stdio.h>

int main(void)
{
  printf("Hello, world!");
  return 0;
}

Then, I type into the terminal make hello or mingw32-make hello, and this is outputted:

cc     hello.c   -o hello
process_begin: CreateProcess(NULL, cc hello.c -o hello, ...) failed.
make (e=2): El sistema no puede encontrar el archivo especificado. (System couldn't find the specified file)
make: *** [<builtin>: hello] Error 2

If I instead put make hello.c or mingw32-make hello.c, this is outputted:

make/mingw32-make: Nothing to be done for 'hello.c'.

However, using gcc command does work, so I don't know what to do. If anyone knows what to do, pls help. Thanks!

Joaquin
  • 91
  • 1
  • 14
  • 3
    Make is not a compiler. Make is a build control tool, that INVOKES a compiler. A compiler is a totally different program that you must install separately. In this case, make is trying to invoke the compiler `cc` which apparently doesn't exist on your system. So either you haven't installed a C compiler, or else you have installed one but it's not called `cc` in which case you have to tell make what it IS called (typically by setting the `CC` variable in your makefile or on the make command line). – MadScientist Apr 26 '21 at 20:37

1 Answers1

0

Call make with this command line:

make CC=gcc hello

The built-in rules to compile a C program use CC as the macro for the compiler, and it is cc by default.

However, if your project grows, you will need to create a makefile. Please read make's documentation and some tutorials to learn how to do this. This makefile will replace some of the built-in rules with your own, and you will be able to define GCC as the compiler.

the busybee
  • 10,755
  • 3
  • 13
  • 30
  • Oh ok, thanks. Is there a way to make the gcc the default macro for the compiler? (My projects isn't gonna grow cause I was just trying to run some old CS50 files from my computer, but I don't think I'll use C for something "real") – Joaquin Apr 29 '21 at 00:50
  • Well, make is open source. You can fetch its source and change it. -- I don't have time currently to look into it, but the documentation might say something. For example, you might set an environment variable. -- A makefile is really simple for such simple project as you seem to plan. -- Several years ago I even used make's option `-r` to disable all built-in rules to be sure to have anything defined in my makefile. – the busybee Apr 29 '21 at 07:42