我有4个.c文件hello.c,here.c,bye.c和main.c。一个头文件mylib.h
内容如下
hello.c
#include<stdio.h>
void hello()
{
    printf("Hello!\n");
}here.c
#include<stdio.h>
void here()
{
     printf("I am here \n");
}bye.c
#include<stdio.h>
void bye()
{
    printf("Bye,Bye");
}main.c
#include<stdio.h>
#include "mylib.h"
int main()
{ 
  hello();
  here();
  bye();
  return 1;
}mylib.h
#ifndef _mylib_
#define _mylib_
void hello();
void here();
void bye();
#endif用于创建静态库的makefile是: Makefile
all:    myapp
#Macros
#Which Compiler
CC = g++
#Where to install
INSTDIR = /usr/local/bin
#Where are include files kept
INCLUDE = .
#Options for developement
CFLAGS = -g -Wall -ansi
#Options for release
#CFLAGS = -O -Wall -ansi
#Local Libraries
MYLIB = mylib.a
myapp:  main.o $(MYLIB)
    $(CC) -o myapp main.o $(MYLIB)
$(MYLIB):       $(MYLIB)(hello.o) $(MYLIB)(here.o) $(MYLIB)(bye.o)
main.o:         main.c mylib.h
hello.o:        hello.c
here.o:         here.c
bye.o:          bye.c
clean:
    -rm main.o hello.o here.o bye.o $(MYLIB)
install:        myapp
    @if [ -d $(INSTDIR) ]; \
    then \
            cp myapp $(INSTDIR);\
            chmod a+x $(INSTDIR)/myapp;\
            chmod og-w $(INSTDIR)/myapp;\
            echo "Installed in $(INSTDIR)";\
    else \
            echo "Sorry, $(INSTDIR) does not exist";\
    fi问题:当我执行以下命令时
make -f Makefile all 我得到以下依赖错误:
make: Circular mylib.a <- mylib.a dependency dropped.
ar rv (hello.o) hello.o
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `ar rv (hello.o) hello.o'
make: *** [(hello.o)] Error 2问题:How do I resolve this? Which command is causing the cyclic dependency?
发布于 2010-10-16 04:02:09
在依赖项列表中删除无关的$(MYLIB)。这就是:
$(MYLIB):       $(MYLIB)(hello.o) $(MYLIB)(here.o) $(MYLIB)(bye.o)应该是:
$(MYLIB):       hello.o here.o bye.ohttps://stackoverflow.com/questions/3945650
复制相似问题