c - linux下如何创建makefile

标签 c makefile autoconf automake

我有以下内容:一个 .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/

相关文章:

c - 通过 AC_DEFINE 给宏一个整数值

autotools - "Help"字符串变量替换为 "configure --help"

testing - 将模块与 makefile (Ocaml) 结合使用时出现问题

c - 为什么 C 有单独的标签和标识符的 namespace ?

c++ - C、C++ : Shared libraries: Are single functions or complete libraries loaded into memory?

c - 使用指针的段错误(核心转储)

Makefile 教程中令人困惑的 Sed 单行代码

c++ - 函数的多重定义,为什么守卫没有捕获这个?

c - autoconf configure 导致 C std lib header 相关的编译错误

c - 你什么时候使用 uint_least16_t