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

时间:2012-03-09 16:13:22

标签: c++ linux makefile static-libraries

我有简单的文件: hello.h,hello.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 ++:致命错误:没有输入文件     编译终止

1 个答案:

答案 0 :(得分:3)

我不认为$>意味着什么特别的,将其更改为$<,它扩展到规则的第一个先决条件。 (在这种情况下为hello.cpp)