-
makefile problem
I am writing a make file for .c files
I want to be able to execute it on Linux.
It makes many files, so for simplicity, I've eliminated most of them and placed a few dummy names so you can see the structure of the makefile
The .a file gets made, but at least one problem I have is that the .so file is not made.
Can anyone see the problem?
---------------------------------------------------------
OBJDIR=obj
SRCDIR=src
libMine.a : $(OBJDIR)/myfile1.o $(OBJDIR)/myfile2.o $(OBJDIR)/main.o
ar -rc libMine.a $(OBJDIR)/myfile1.o $(OBJDIR)/myfile2.o $(OBJDIR)/main.o
$(OBJDIR)/myfile1.o : $(SRCDIR)/myfile1.c
g++ -fPIC -o$(OBJDIR)/myfile1.o -c -Iincludes $(SRCDIR)/myfile1.c
$(OBJDIR)/myfile2.o : $(SRCDIR)/myfile2.c
g++ -fPIC -o$(OBJDIR)/myfile2.o -c -Iincludes $(SRCDIR)/myfile2.c
$(OBJDIR)/main.o : $(SRCDIR)/main.c
g++ -fPIC -o$(OBJDIR)/main.o -c -Iincludes $(SRCDIR)/main.c
all : libMine.a
clean :
-rm libMine.a $(OBJDIR)/myfile1.o $(OBJDIR)/myfile2.o $(OBJDIR)/main.o
ld -shared -soname libMine.so.1 -o libMine.so.1.0 -lc $(OBJDIR)/ $(OBJDIR)/myfile1.o $(OBJDIR)/myfile2.o $(OBJDIR)/main.o
ldconfig -v -n .
-
Well putting the clean dependency in the middle of your all dependency can't be helping matters.
-
so, changing that order like so:
OBJDIR=obj
SRCDIR=src
libMine.a : $(OBJDIR)/myfile1.o $(OBJDIR)/myfile2.o $(OBJDIR)/main.o
ar -rc libMine.a $(OBJDIR)/myfile1.o $(OBJDIR)/myfile2.o $(OBJDIR)/main.o
$(OBJDIR)/myfile1.o : $(SRCDIR)/myfile1.c
g++ -fPIC -o$(OBJDIR)/myfile1.o -c -Iincludes $(SRCDIR)/myfile1.c
$(OBJDIR)/myfile2.o : $(SRCDIR)/myfile2.c
g++ -fPIC -o$(OBJDIR)/myfile2.o -c -Iincludes $(SRCDIR)/myfile2.c
$(OBJDIR)/main.o : $(SRCDIR)/main.c
g++ -fPIC -o$(OBJDIR)/main.o -c -Iincludes $(SRCDIR)/main.c
all : libMine.a
ld -shared -soname libMine.so.1 -o libMine.so.1.0 -lc $(OBJDIR)/ $(OBJDIR)/myfile1.o $(OBJDIR)/myfile2.o $(OBJDIR)/main.o
ldconfig -v -n .
clean :
-rm libMine.a $(OBJDIR)/myfile1.o $(OBJDIR)/myfile2.o $(OBJDIR)/main.o
It now gives the error:
ld -shared -soname libMine.so.1 -o libMine.so.1.0 -lc obj/myfile1.o \
ld: : No such file: No such file or directory
Does this mean it can find myfile1.o in the obj directory?
It is definitely there.
-
You need to use code tags (see announcements)
It's impossible to tell if you've even got a valid makefile, with all the snipping you do, and all the HTML formatting the board does.
-
each comand must have a single tab char before it in the same line.
declare clean as .PHONY:
put all dependancies first and extras later.