首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建Makefile以一次编译%2个文件

创建Makefile以一次编译%2个文件
EN

Stack Overflow用户
提问于 2014-12-04 05:23:29
回答 1查看 50关注 0票数 0
代码语言:javascript
复制
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来一次性编译所有内容。然而,它并不成功。我不知道这是怎么回事。你能给我一张照片吗。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2014-12-04 10:23:06

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27281910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档