gpt4 book ai didi

c++ - 使用 linux g++ 编译器在 makefile 中创建静态库

转载 作者:太空宇宙 更新时间:2023-11-04 09:06:41 24 4
gpt4 key购买 nike

我有简单的文件:你好.h,你好.cpp

我已经创建了一个 makefile 来生成一个静态库 (libhello.a)但我收到错误消息,我做错了什么?

我的代码是:

CC = g++
CFLAGS = -Wall -g
utilObjs = hello.o

libhello.a: $(utilObjs)
ar rc $@ $(utilObjs)
ranlib $@

hello: hello.o libhello.a
$(CC) $(CFLAGS) hello.o -L ./ -lutil -o $@

hello.o: hello.cpp hello.h
$(CC) $(CFLAGS) -c $>

clean:
rm -rf *.o libhello.a hello

all: hello
.PHONY: all clean

错误信息: g++: fatal error : 没有输入文件 编译终止

最佳答案

我不认为$>意味着什么特别的,把它改成$< ,它扩展到规则的第一个先决条件。 (在本例中为 hello.cpp)

关于c++ - 使用 linux g++ 编译器在 makefile 中创建静态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9637325/

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