I have 4 .c files hello.c
,here.c
,bye.c
and main.c
.
One header file mylib.h
The contents are as follows
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
The makefile for creating a static lib is : 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
Problem: When I execute the command
make -f Makefile all
I get the following dependecy error:
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
Questions : How do I resolve this? Which command is causing the cyclic dependency?