2014-12-03 44 views
0
If I compile by hand, my code should be 
gcc image.c -c 
gcc stego.c -c 
gcc image.c stego.c -o Stego 

然后我尝试创建一个Makefile来一次编译所有内容。但是,这并不成功。我不知道这有什么问题。你能否给我一个礼物?立即创建Makefile以编译2个文件

GCC=gcc 
all:Stegonew 
Stegonew:stego.o image.o 
     ${GCC} stego.o image.o -o Stegonew 
stego.o: stego.c image.h 
     ${GCC} stego.c -c 
image.o:image.c 
     ${GCC} image.c -c 
clean: 
     rm *.o Stegonew 
+1

你看到的是什么错误?而且你*在命令行中使用制表符(不是空格),对吗? ('$ {GCC} stego.c'等) – 2014-12-03 21:34:22

+0

感谢您的回答。我得到了错误信息:“不知道如何制定目标Stegonew”。 @PaulRoub – SunnyTrinh 2014-12-03 21:50:49

+0

你尝试过'make -j2'吗? – 2014-12-04 02:28:20

回答

0
notice that all indented lines are actual a single leading tab char 
lots more could be added to this makefile to yield a more flexable result 
but the following should do the job 

* give full path use ':' so only evaluated once 
* following path value is for linux 
GCC := /usr/bin/gcc 
RM := /usr/bin/rm 

* tell make that certain targets will not produce a file of the same name 
.PHONY: all clean 

* this target will be performed if user only enters 'make' 
all:Stegonew 

* link the executable, 
* are any libraries needed? 
* if so, set path by: '-Lpath' set library by '-llibname' 
* where libname is missing leading 'lib' chars and trailing '.so' characters 
* of actual library name 
Stegonew:stego.o image.o 
     ${GCC} stego.o image.o -o Stegonew 

* compile the stego.c file, 
* '-I.' says to look for source code line: #include "image.h" in current directory 
* '-c' says compile only 
stego.o: stego.c image.h 
     ${GCC} -c stego.c -o stego.o -I. 

* compile the image.c file, 
* '-I.' says to look for source code line: #include "image.h" in current directory 
* '-c' says compile only 
image.o:image.c image.h 
     ${GCC} -c image.c -o image.o -I. 

* target for removing the re-producable files 
* '-f' forces the removal without asking user for approval 
clean: 
     $(RM) -f *.o Stegonew