我有以下内容:一个 .c 代码、一个 .h 代码加上一个 .o 文件和一个 -lib... 库。当我用 gcc 编译 c 代码时,我这样做:
gcc code.c -o code file.o -library
如何创建 makefile?
我目前使用 autoconf 和 automake?
我目前有:
Makefile
all:
gcc code.c -o code file.o -library
clean:
rm -f code
当我编译 make 时,我得到:
make: Nothing to be done for `all'.
需要一些帮助。谢谢
最佳答案
很抱歉我必须给出这个答案,但是你尝试过https://www.google.com/search?q=makefile+tutorial吗? ?
选择一个,并学习如何创建 Makefile。您不需要自动工具。
我花了 5 分钟阅读 Makefile Tutorial 才想出这个答案。 :
CC=gcc
CFLAGS=-Wall
CLIBS=-lX11
OUT=code
OBJS=code.o file.o
$(OUT): code.o file.o
$(CC) $(CFLAGS) $(CLIBS) -o $(OUT) $(OBJS)
code.o: code.c
$(CC) $(CFLAGS) -c code.c -o code.o
file.o: file.c
$(CC) $(CFLAGS) -c file.c -o file.o
.PHONY: clean
clean:
rm -rf *.o $(OUT)
If on the computer the -library doesn t exist I want to install it automatically.
这特定于所使用的发行版,并且您需要计算机上的 root 访问权限。这样做不是这样做的。相反,您应该创建一个特定于您的发行版的包,并在其中指定依赖项。
例如,对于 Ubuntu(因为它是最常用的发行版),您需要创建一个 .deb 文件:http://wiki.debian.org/IntroDebianPackaging
但是,这与您最初的问题无关。
关于c - linux下如何创建makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12597102/