gpt4 book ai didi

c - make 不成文的规则

转载 作者:行者123 更新时间:2023-11-30 17:01:21 24 4
gpt4 key购买 nike

这是我的 makefile 代码:

CC      = gcc
IFLAGS = -Iinclude
CFLAGS = -std=c99 -fPIC -pedantic -Wall -Wextra -c # -march=native -ggdb3
LFLAGS = -shared -lX11 # -march=native -ggdb3
DFLAGS = -L./lib -lOSPOOC

TARGET = lib/libOSPOOC.so
SOURCES = $(shell echo src/*.c)
HEADERS = $(shell echo include/*.h)
OBJECTS = $(patsubst %.c,%.o, $(SOURCES))

# CURLIBPATH = $(PWD)/lib
# LDLIBPATH = $(shell echo $(LD_LIBRARY_PATH) | grep $(CURLIBPATH))

all: $(TARGET)

$(TARGET): $(OBJECTS)
$(CC) $(LFLAGS) -o $(TARGET) $(OBJECTS)

*.o: *.c
echo allo
$(CC) $(IFLAGS) $(CFLAGS) -o $@ $<

demo: $(TARGET) demo/windows.c
$(CC) $(IFLAGS) -o bin/windows demo/windows.c $(DFLAGS)

clean:
rm -r */*.o */*.so bin/*

规则 *.o 没有被调用,而且,我不知道如何,但它编译正确......

结果:

make demo
gcc -std=c99 -fPIC -pedantic -Wall -Wextra -c -c -o src/OSPobj.o src/OSPobj.c
gcc -std=c99 -fPIC -pedantic -Wall -Wextra -c -c -o src/OSPutl.o src/OSPutl.c
gcc -std=c99 -fPIC -pedantic -Wall -Wextra -c -c -o src/OSPwin.o src/OSPwin.c
gcc -shared -lX11 -o lib/libOSPOOC.so src/OSPobj.o src/OSPutl.o src/OSPwin.o
gcc -Iinclude -o bin/windows demo/windows.c -L./lib -lOSPOOC

问题是 -c 使用了两次,并且 echo allo 没有被调用...

我不明白什么,为什么我会有这种奇怪的行为?

最佳答案

好吧,这不是 *.o: *.c 而是 %.o: %.c

*.o 用于 bash,%.o 用于 make

关于c - make 不成文的规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37125118/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com