1

I am just starting out with C and now I am at the part where I want to learn about Makefiles. I am starting out small but already failing ;)

I have a very simple Makefile which just compiles the main.c to a main.o and then to an executable. But I get an error saying I have a syntax error. I use g++.

The command that i use are:

g++ make Makefile << name of the make file 

And the Makefile is set up like this:

main.o: main.c main.h [TAB] g++ -c main.c main: main.o [TAB] g++ main.o -o main 
3
  • 1
    If you're using C, you should use gcc instead of g++ (but it's still wrong for a makefile). Commented Jan 2, 2013 at 12:47
  • I am on windows, i thought g++ is the windows version of gcc. I got it from MinGW Commented Jan 2, 2013 at 12:49
  • No, both gcc (C Compiler) e g++ (C++ compiler) are part of GCC (GNU Compiler Collection), and they are both in the MinGW porting. Commented Jan 2, 2013 at 13:00

1 Answer 1

3

To run make on the Makefile (the default name), invoke the make command:

$ make 

Don't try to call g++ with the makefile, the compiler knows nothing about makefiles.

EDIT: You say you don't have the make command, in a comment. Then you need to get it. :) There are several versions of make for Windows, here is GNU make (which is common in Linux and other Unix-like environments) ported to Windows.

Sign up to request clarification or add additional context in comments.

1 Comment

I am a novic in all of does commands, but my windows doesn't have ( probaly i am not doing it correct ) command make?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.