2012-03-09 98 views
0

我有简单的文件: hello.h,HELLO.CPP在makefile创建静态库,使用Linux G ++编译器

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

我的代码是:

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

libhello.a: $(utilObjs) 
    ar rc [email protected] $(utilObjs) 
    ranlib [email protected] 

hello: hello.o libhello.a 
    $(CC) $(CFLAGS) hello.o -L ./ -lutil -o [email protected] 

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

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

all: hello 
.PHONY: all clean 

错误消息: G ++:致命错误:没有输入文件 编译终止

+0

默认的GNU * make *规则(你可以通过'make -p'获得它们)已经有了编译C++的规则,使用'CXX'而不是'CC'等。使用'remake'来帮助调试'Makefile' – 2012-03-09 17:16:32

回答

3

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