views:

30

answers:

3

I have 3 files Head.cpp , Head.h and Hello.cpp . I am trying to build a make for the compilation process. My makefile is make.w

Hello :   Head.o Hello.o
          g++ -o Head.o Hello.o

Head.o :  Head.cpp
          g++ -o Head.cpp

Hello.o:  Hello.cpp
          g++ -o Hello.cpp

every time I type the command make make.w - I get " Nothing to make fot make.w" . I dont get why this is happening and how to resolve the same.

+1  A: 

You need a -f in front of the makefile name.

make -f make.w

You may want to specify the target to be built as well

make -f make.w Hello
Andrew Cooper
+2  A: 

make make.w means "Make target make.w in default makefile named Makefile".

You want to specify your makefile, so you want make -f make.w

birryree
A: 

Since you are calling the make with a non-default make file which is makefile or Makefile you need to use the -f option as:

make -f make.w
     ^^

Looks like you are currently calling it as:

make make.w

which does not work. It tell make to make the target make.w in the default makefile.

Also When converting from .c to .o you need to use the -c compiler flag which tells the compiler to just compile but don't link. Also when using -c you don't need -o, the compiler will generate the <filename>.o for you.

Head.o :  Head.cpp
          g++ -c  Head.cpp
              ^^

Hello.o:  Hello.cpp
          g++ -c  Hello.cpp
              ^^

And finally you are missing the name of the executable Hello on the compile line:

Hello :   Head.o Hello.o
          g++ -o Head Head.o Hello.o
                 ^^^^
codaddict
Now, I get an ` make -f mkfl.wg++ -o Head Head.cpp/usr/lib/gcc/x86_64-linux-gnu/4.3.1/../../../../lib/crt1.o: In function `_start':(.text+0x20): undefined reference to `main'collect2: ld returned 1 exit statusmake: *** [Head.o] Error 1` error
Eternal Learner
I've updated the answer, you need to use `-o` option as shown.
codaddict
Thanks, I tried to compile it after making changes and get the following error g++ -c -o Head Head.cppg++ -c -o Hello Hello.cppg++ -c -o Head.o Hello.og++: Hello.o: No such file or directoryg++: no input filesmake: *** [ram] Error 1
Eternal Learner
I've updated my answer. You don't need the `-o` option, just use `-c`.
codaddict
Thanks, helps a lot. Also I am looking for good tutorials to build shared and static libraries. Do you suggest reading any particular articles?
Eternal Learner