makefile

Discussion in 'C++' started by Ian, Aug 14, 2005.

  1. Ian

    Ian Guest

    Juhan Voolaid wrote:
    > Hello
    >
    > I need help with my makefile, so that when I compile my project the
    > source code files would be separated from the object (*.o) files.
    >

    OT here, try comp.unix.programmer.

    Ian
    Ian, Aug 14, 2005
    #1
    1. Advertising

  2. Hello

    I need help with my makefile, so that when I compile my project the
    source code files would be separated from the object (*.o) files.

    So if I have: main.cpp and classes.cpp - the filestructure should be
    like that:
    project_dir/
    source_dir/
    main.cpp
    classes.cpp
    makefile
    main.o
    classes.o
    .program_exec

    My current makefile is quite good as it compiles only the source, that
    is edited. Problem is that all the files are in same directory. I'd like
    that the makefile should do the same thing, only with this add on that
    it keeps the source files from other compiled files separeted.
    #########################
    # makefile #
    #########################
    CC=g++
    CFLAGS=-c -Wall
    LDFLAGS=
    SOURCES=main.cpp classes.cpp
    OBJECTS=$(SOURCES:.cpp=.o)
    EXECUTABLE=program_exec

    all: $(SOURCES) $(EXECUTABLE)

    $(EXECUTABLE): $(OBJECTS)
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@

    ..cpp.o:
    $(CC) $(CFLAGS) $< -o $@

    makfile:
    Juhan Voolaid, Aug 14, 2005
    #2
    1. Advertising

  3. Juhan Voolaid wrote:
    > Hello
    >
    > I need help with my makefile, so that when I compile my project the
    > source code files would be separated from the object (*.o) files.


    As mentioned - this is OT here.

    However, take a look at MakeXS. http://www.makexs.com (shameless plug).
    It can do this if you need to. MakeXS is just a GNU Makefile but
    rather extreme.

    >
    > So if I have: main.cpp and classes.cpp - the filestructure should be
    > like that:
    > project_dir/
    > source_dir/
    > main.cpp
    > classes.cpp
    > makefile
    > main.o
    > classes.o
    > .program_exec
    >
    > My current makefile is quite good as it compiles only the source, that
    > is edited. Problem is that all the files are in same directory. I'd like
    > that the makefile should do the same thing, only with this add on that
    > it keeps the source files from other compiled files separeted.
    > #########################
    > # makefile #
    > #########################
    > CC=g++
    > CFLAGS=-c -Wall
    > LDFLAGS=
    > SOURCES=main.cpp classes.cpp
    > OBJECTS=$(SOURCES:.cpp=.o)
    > EXECUTABLE=program_exec
    >
    > all: $(SOURCES) $(EXECUTABLE)
    >
    > $(EXECUTABLE): $(OBJECTS)
    > $(CC) $(LDFLAGS) $(OBJECTS) -o $@
    >
    > .cpp.o:
    > $(CC) $(CFLAGS) $< -o $@
    >
    > makfile:
    Gianni Mariani, Aug 14, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MACEI'S
    Replies:
    0
    Views:
    1,324
    MACEI'S
    Jul 10, 2003
  2. Karthik
    Replies:
    0
    Views:
    389
    Karthik
    Apr 29, 2004
  3. Karthik
    Replies:
    0
    Views:
    610
    Karthik
    Apr 29, 2004
  4. Replies:
    16
    Views:
    1,125
  5. Java Makefile

    , Dec 15, 2005, in forum: Java
    Replies:
    23
    Views:
    3,713
    Jean-Francois Briere
    Dec 27, 2005
Loading...

Share This Page