我不熟悉makefile,但习惯于简单的.现在,我手边有一项任务.
我需要编译和链接测试应用程序与不同的库和基于给定目标的不同包含路径.如果target是TARGET1,则在编译期间链接LIB1并包含INCLUDEPATH1.类似地,如果给定的目标是TARGET2,则在CFLAGS中使用INCLUDEPATH2进行编译并与LIB2链接.
%.o: %.c
@echo [CC] $< ...
$(CC) $(CFLAGS) -o $*.o $<
Run Code Online (Sandbox Code Playgroud)
现在我有一个如上所述的规则来编译我的测试应用程序.现在,如何根据目标更改CFLAGS.
可能重复:
编译glib时链接器错误...?
好的,我知道这可能是重复的,但我找不到任何其他问题的答案.我正在尝试安装Pintos,当我在src/utils目录中运行'make'时,我得到的错误是对'floor'有一个未定义的引用.我检查了makefile,这是我得到的:
all: setitimer-helper squish-pty squish-unix
# 2207718881418
CC = gcc
CFLAGS = -Wall -W
LDFLAGS = -lm
setitimer-helper: setitimer-helper.o
squish-pty: squish-pty.o
squish-unix: squish-unix.o
clean:
rm -f *.o setitimer-helper squish-pty squish-unix
Run Code Online (Sandbox Code Playgroud)
我尝试添加LIBS = -lm,但这没有帮助.
make的输出:
gcc -lm setitimer-helper.o -o setitimer-helper
setitimer-helper.o: In function `main':
setitimer-helper.c:(.text+0xbb): undefined reference to `floor'
collect2: ld returned 1 exit status
make: *** [setitimer-helper] Error 1
Run Code Online (Sandbox Code Playgroud)
这种困境的任何解决方案?