gpt4 book ai didi

c - bmake : Proper use of Automatic Variables

转载 作者:太空狗 更新时间:2023-10-29 15:04:29 25 4
gpt4 key购买 nike

CC = gcc
CFLAGS = -std=c99 -Werror
VPATH = ./src:./include

.MAIN: libstring.so
.PHONY: clean

libstring.o: libstring.c libstring.h
$(CC) $(CFLAGS) -c $< -I ./include -o $@

libstring.so: libstring.o
$(CC) -fPIC -shared $< -o $@

clean:
rm -rf ./*.o ./*.so

在上面的代码片段中,我特别感兴趣的是我是否使用了 <自动变量正确。如果源/先决条件是 c 源文件,则此方法有效,但目标文件似乎失败。

编译时出现错误:

gcc -fPIC -shared  -o libstring.so
gcc: No input files specified

最佳答案

确定您正在使用 GNU make 吗?您编写的代码将在 GNU make 中如您所愿地工作。但是,其他版本的 make 不支持显式规则中的自动变量,仅支持后缀(隐式)规则。例如,如果您使用的是 SunOS/Solaris make,则 $<在明确的规则下将为空。

关于c - bmake : Proper use of Automatic Variables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12904011/

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