Thread: makefile problem

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    2

    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 .

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well putting the clean dependency in the middle of your all dependency can't be helping matters.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    2
    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.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. problem with Makefile separator
    By luca in forum Tech Board
    Replies: 6
    Last Post: 01-15-2007, 10:20 AM
  3. Problem with makefile, how to use the -lm oh this?
    By Nazgulled in forum C Programming
    Replies: 1
    Last Post: 04-07-2006, 01:29 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM