Makefile Help

This is a discussion on Makefile Help within the Tech Board forums, part of the Community Boards category; Hello again guys. I would just like to ask for some help regarding the makefile I used for the inttohex ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    11

    Makefile Help

    Hello again guys. I would just like to ask for some help regarding the makefile I used for the inttohex program. It would not work and it would just say Missing separator. Stop..

    Hope somebody could help. Here's the makefile:

    Code:
    # makefile for exercise on linked lists, files, searching and sorting
    CC=gcc
    CFLAGS=-g -W -Wall -I.
    OBJECTS=inttohex.o
    HEADERS=
    PROGNAME=inttohex
    
    $(PROGNAME): $(OBJECTS)
            $(CC) $(CFLAGS) $(OBJECTS) -o $(PROGNAME)
    
    inttohex.o: inttohex.c $(HEADERS)
            $(CC) -c $(CFLAGS) -o inttohex.o
    
    
    .PHONY: clean ctags
    
    tags: ctags
    
    ctags:
            ctags -R
    
    clean:
            rm -rf $(OBJECTS) $(PROGNAME)

  2. #2
    Registered User
    Join Date
    Jan 2006
    Location
    Europe/Belgrade
    Posts
    78
    That's because you're using spaces instead of tabs in lines where command has to be executed. For example
    Code:
            $(CC) $(CFLAGS) $(OBJECTS) -o $(PROGNAME)
    must be indented with tab not with 8 spaces.
    Beside this, in the line
    Code:
            $(CC) -c $(CFLAGS) -o inttohex.o
    you are not giving the source file to the compiler, so it cannot compile. Add inttohex.c after -c flag:
    Code:
             $(CC) -c inttohex.c $(CFLAGS) -o inttohex.o
    Maybe there are more errors, that's what I saw immediately.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You shouldn't need to pass -r to rm, because I don't think it's going to be passed any directories.

    Also, there is an implicit rule to compile .c files into .o files, so you can just use this:
    Code:
    inttohex.o: inttohex.c $(HEADERS)
    leaving out the "$(CC) -c $(CFLAGS) -o inttohex.o".
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,436
    Moved to Tech Board since it does not directly concern C programming.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile Problem: None rule to make target
    By chris24300 in forum Linux Programming
    Replies: 25
    Last Post: 06-17-2009, 09:45 AM
  2. Building a project using a Makefile
    By starcatcher in forum Windows Programming
    Replies: 2
    Last Post: 11-23-2008, 10:50 PM
  3. unix makefile won't work but works in Dev C++
    By jk1998 in forum C++ Programming
    Replies: 1
    Last Post: 06-09-2007, 03:54 PM
  4. makefile blues....
    By WaterNut in forum C Programming
    Replies: 6
    Last Post: 05-30-2005, 08:22 PM
  5. Need help with Makefile
    By xshapirox in forum C++ Programming
    Replies: 14
    Last Post: 09-28-2004, 03:32 PM

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