makefile problem

This is a discussion on makefile problem within the C Programming forums, part of the General Programming Boards category; I am writing a make file for .c files I want to be able to execute it on Linux. It ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    #include<xErath.h> xErath's Avatar
    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, 09: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, 05:24 PM
  5. Replies: 5
    Last Post: 11-07-2005, 10:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21