Can't add a path to makefile in Windows

This is a discussion on Can't add a path to makefile in Windows within the C Programming forums, part of the General Programming Boards category; Hi all, I'm learning how to use makefile to build an executable file in Windows 7. The compiler I used ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    3

    Can't add a path to makefile in Windows

    Hi all,
    I'm learning how to use makefile to build an executable file in Windows 7. The compiler I used is mingw32. I followed the examples 18-1 to 18-3 from the book <Practical C Programming>. Three files were used here: ia.c ia.h, and hist.h. This book provides some makefile examples and they work fine as long as I put all three files and makefile under one folder.
    However, I wanted to see if I could make it when putting source files and header files into seperate folders. So I followed the traditional layout mentioned in the GNU make manual:
    Code:
    ~/hist
    |>---- Makefile
    |>---- include
    | |>---- ia.h
    |>---- src
    | |>---- hist.c
    | |>---- ia.c
    Now, I should use VPATH/vpath or -I../path. So I tried different combinations, but all of them failed. I really don't know why. Here's my makefile:
    Code:
    VPATH = C:\hist\include
    Srcdir = -I C:\hist\src
    CC = gcc
    CFLAGS = -g -Wall
    all: hist
    hist: hist.o ia.o
      $(CC) $(CFLAGS) -o hist hist.o ia.o
      
    hist.o: hist.c ia.h
      $(CC) $(Srcdir) $(CFLAGS) -c hist.c
      
    ia.o: ia.c ia.h
      $(CC) $(Srcdir) $(CFLAGS) -c ia.c
    clean:
      rm -f hist hist.o ia.o
    -----------------------------------
    The mingw gives me this error:
    -----------------------
    $ make
    make: *** No rule to make target `hist.c', needed by `hsit.o'. Stop.
    ----------------------------------
    I also tried the following possibility:
    -----------------------------------
    IDIR = -I C:\hist\include
    SDIR = -I C:\hist\src
    CC = gcc
    CFLAGS = -g -Wall
    all: hist
    hist: hist.o ia.o
      $(CC) $(CFLAGS) -o hist hist.o ia.o
      
    hist.o: hist.c ia.h
      $(CC) $(CFLAGS) -c c:\hist\src\hist.c ia.h
      
    ia.o: ia.c ia.h
      $(CC) $(CFLAGS) -c ia.c ia.h
    clean:
      rm -f hist hist.o ia.o
    I got the same error. Then I tested the vpath method:
    Code:
    vpath %.c src
    vpath %.h include
    CC = gcc
    CFLAGS = -g
    srcf := hist.c ia.c
    obj := hist.o ia.o
    %: %.c
     $(obj) $^ -o $@
      
    %.o: %.c
     $(srcf) $(obj) $<
    clean:
      rm -f ia
    Now I got no error, and the Mingw gives me this output:
    Code:
    $ make
    rm -f ia
    # gcc -g -o hist hist.o ia.o
    # gcc -g -c c:\hist\src\hist.c ia.h
    # gcc -g -c ia.c ia.h
    # rm -f hist hist.o ia.o
    # gcc -g -o hist hist.o ia.o
    # gcc -g -c hist.c
    # gcc -g -c ia.c
    # rm -f hist hist.o ia.o
    Regarding the vpath method, I tried the following ways too:
    Code:
    vpath %.c c:\hist\src
    vpath %.h c:\hist\include
    ----------------------------
    vpath %.c c:\\hist\\src
    vpath %.h c:\\hist\\include
    -------------------------------
    vpath %.c c:/hist/src
    vpath %.h c:/hist/include
    Mingw gave me same output as above.
    So what should I do to add the path? Any form of help would be appreciated! Thanks for reading.
    Last edited by tongjie; 06-16-2012 at 01:58 PM.

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by tongjie View Post
    However, I wanted to see if I could make it when putting source files and header files into seperate folders. So I followed the traditional layout mentioned in the GNU make manual:
    Code:
    ~/hist
    |>---- Makefile
    |>---- include
    | |>---- hist.h
    | |>---- ia.h
    |>---- src
    | |>---- ia.c
    Where is "hist.c"?
    Last edited by AndiPersti; 06-16-2012 at 01:50 PM. Reason: uppercase tag names

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    3
    Quote Originally Posted by AndiPersti View Post
    Where is "hist.c"?
    Oh, sorry for the typo... It's under folder src. There's no hist.h. I'm editting the original post.

  4. #4
    Registered User
    Join Date
    Jun 2012
    Posts
    3
    The VPATH works. I just didn't do it right. Here is the code of the makefile:
    Code:
    VPATH = C:\hist\include c:\hist\src
    CC = gcc
    CFLAGS = -g -Wall -I c:\hist\include
    all: hist
    hist: hist.o ia.o
      $(CC) $(CFLAGS) -o hist hist.o ia.o
      
    hist.o: hist.c ia.h
      $(CC) $(CFLAGS) -c $^
      
    ia.o: ia.c ia.h
      $(CC) $(CFLAGS) -c $<
    clean:
      rm -f hist hist.o ia.o
    Thanks to every one who showed interest to this thread!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. makefile and windows compilation
    By inkare in forum C Programming
    Replies: 33
    Last Post: 07-18-2008, 06:55 PM
  2. difference makefile makefile.am makefile.in
    By Bargi in forum Linux Programming
    Replies: 7
    Last Post: 10-28-2007, 02:08 PM
  3. makefile
    By bazzano in forum C Programming
    Replies: 7
    Last Post: 04-16-2006, 03:22 AM
  4. makefile
    By sworc66 in forum C Programming
    Replies: 2
    Last Post: 09-07-2003, 05:44 PM
  5. Makefile?
    By AKira in forum C Programming
    Replies: 3
    Last Post: 11-02-2001, 01:48 AM

Tags for this Thread


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