c - 如何在 OpenBSD 5.8 中使用 makefile

标签 c makefile openbsd

当我键入 make 时,什么也没有发生。如果我用 Linux Ubuntu 来做,那么 make 会构建我的项目。为什么它不能与 BSD 一起使用?生成文件是:

##################################################
## General configuration
## =====================

# Every Makefile should contain this line:
SHELL=/bin/sh

# Program for compiling C programs. 
CC=gcc

# What allocation strategy to use, and number of quick fit lists.
STRATEGY=4
NRQUICKLISTS=6

# Extra flags to give to the C preprocessor and programs that use it (the C and Fortran compilers). 
CFLAGS=-DSTRATEGY=$(STRATEGY) -DNRQUICKLISTS=$(NRQUICKLISTS)

# Default plus extra flags for C preprocessor and compiler.
all_cflags=$(CFLAGS) -Wall -Wextra -ansi -O4

# Malloc source file to use. Set to empty (with `make MALLOC=`) for system default.
MALLOC=malloc.c


##################################################
## Setup files variables
## =====================

# Source files to compile and link together
srcs=$(MALLOC) tstalgorithms.c tstcrash.c tstcrash_complex.c tstcrash_simple.c \
     tstextreme.c tstmalloc.c tstmemory.c tstmerge.c tstrealloc.c \
     tstbestcase.c tstworstcase.c

# Executables
execs=$(patsubst tst%.c, tst%, $(filter tst%.c, $(srcs)))


##################################################
## Ordinary targets
## ================

# http://www.gnu.org/software/make/manual/make.html#Phony-Targets
# These are not the name of files that will be created by their recipes.
.PHONY: all clean

all: $(execs)

tst%: tst%.o $(MALLOC:.c=.o)
    $(CC) $(all_cflags) -o $@ $^

# These programs can not be compiled as ANSI-standard C.
tst%.o: tst%.c
    $(CC) -c $(CFLAGS) $< -o $@

# But the rest should be ANSI-standard C.
%.o: %.c
    $(CC) -c $(all_cflags) $< -o $@

clean:
    -rm -f *.o core $(execs)

这是 session :

$ strings `which make` | grep -B1 MAKE_VERSION
$ which make
/usr/bin/make
$ make -V MAKE_VERSION

$ make
$ ls
Makefile                                tstbestcase_time.gnuplot
README                                  tstcommon.h
README.md                               tstcrash.c
RUN_TESTS                               tstcrash_complex.c
a.out                                   tstcrash_simple.c
best.c                                  tstextreme.c
brk.h                                   tstmalloc.c
first.c                                 tstmemory.c
malloc.c                                tstmerge.c
malloc.h                                tstrealloc.c
quick.c                                 tstworstcase.c
tst.h                                   tstworstcase.dat.tgz
tstalgorithms.c                         tstworstcase_memory.gnuplot
tstbestcase.c                           tstworstcase_time.gnuplot
tstbestcase.dat.tgz                     worst.c
tstbestcase_memory.gnuplot
$ 

如果我输入 make malloc 然后我得到这个我不理解的输出:

$ make malloc
gcc -DSTRATEGY=4 -DNRQUICKLISTS=6   -o malloc malloc.c 
/usr/lib/crt0.o: In function `_start':
(.text+0xa4): undefined reference to `main'
collect2: ld returned 1 exit status
*** Error 1 in /home/niklas/malloc-master (<sys.mk>:85 'malloc')
$ 

最佳答案

那是一个 GNUmakefilepkg_add gmake 然后键入 gmake,或者重写 Makefile 以在 make 下工作。

关于c - 如何在 OpenBSD 5.8 中使用 makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32317408/

相关文章:

c - 在哪里可以找到 "gmp.h"?

regex - Grep 在 OpenBSD 和 Linux 中的行为不同。无法使命令工作

c - 确定与数组中的间隔匹配的值的最快方法

c - C 中对 `SHA1' 的 undefined reference

c - 在 C 中生成文件给出 fatal error

c - 发生错误时如何在makefile中同时退出并记录文件中的数据

python - 如何利用 OpenBSD、Nginx、Python 和 NoSQL

C指向按位和运算符的数组声明的指针

c - 从(汇编)指令序列到 C 代码的映射

c - 错误: declaration does not declare anything [-Werror]|