2014-12-03 3 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' и т. Д.) –

+0

Спасибо за ваш ответ. Я получил сообщение об ошибке: «Не знаю, как сделать цель Stegonew». @PaulRoub – SunnyTrinh

+0

Вы пробовали 'make -j2'? –

ответ

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 
Смежные вопросы