dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: makefile for .c and .h files in different directories

  1. #1
    Join Date
    Apr 2006
    Posts
    20

    Exclamation makefile for .c and .h files in different directories

    Hallo,
    I want to make a program which has the main program and exe in a folder called /Main/ and the .c and .h files in the folders /Main/src and Main/inc

    I am trying to create the make file based on a tutorial i found but since now it is impossible to make it work. Could you please help?

    Here is the makefile:


    IDIR =Main/inc
    SRCDIR=Main/src

    CC=gcc
    CFLAGS=-I$(IDIR)

    ODIR=Main/obj
    LDIR =../lib

    LIBS=-lm

    _DEPS = Main.h
    DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

    _OBJ = Main.o srcFile.o
    OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))

    $(ODIR)/%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)

    Main: $(OBJ)
    gcc -o $@ $^ $(CFLAGS) $(LIBS)

    .PHONY: clean

    clean:
    rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~

  2. #2
    Join Date
    Jan 2009
    Posts
    1,689

    Re: makefile for .c and .h files in different directories

    Why not simply #include them with the path? That would be much better than setting the include directory in the makefile.

  3. #3
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,145

    Re: makefile for .c and .h files in different directories

    Quote Originally Posted by ninja9578 View Post
    That would be much better than setting the include directory in the makefile.
    I disagree. I personally don't like to use relative paths such as
    Code:
    #include "../inc/file.h"
    The makefile should work, because the CFLAGS is containing the -I$(IDIR) directive. But then it is a matter of where the makefile is located, I'd say. The include directory is relative to the makefile's location, so it might not be correctly set if the makefile is in the Main or Main/src directory. It should be above the Main directory.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)