Results 1 to 3 of 3

Thread: How to write a small makefile?

  1. #1
    Join Date
    Feb 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to write a small makefile?

    Hello, I want to write a makefile that compiles each .cpp files with the same command and create an executable file with all .o files.

    Qt Code:
    1. $(OUTPUT): ?dependencies?
    2. $(LINK) $^ -o $@ $(LIBS) $(LFLAGS)
    3.  
    4. $(OBJECTS_DIR)/%.o: $(SOURCES_DIR)/%.cpp $(SOURCES_DIR)/%.hpp
    5. $(CXX) $< -c -o $@ $(INCLUDE) $(CXXFLAGS)
    To copy to clipboard, switch view to plain text mode 

    The problem is the dependencies of the main rule. I tried $(OBJECTS_DIR)/%.o but it does not work. I do not want to write the name of each .o file.
    The dependencies names are all .cpp files that are in $(SOURCES_DIR) folder, with .o suffix instead of .cpp and in $(OBJECTS_DIR) folder.

    Thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to write a small makefile?

    With Gnu make:
    Qt Code:
    1. SOURCES = $(wildcard *.cpp)
    2. OBJECTS = $(SOURCES:.cpp=.o)
    To copy to clipboard, switch view to plain text mode 
    I cannot vouch for other makes.
    Last edited by ChrisW67; 21st March 2012 at 04:04. Reason: Clarified where sources comes from

  3. #3
    Join Date
    Feb 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to write a small makefile?

    Thank you.

Similar Threads

  1. Replies: 0
    Last Post: 3rd September 2011, 07:51
  2. Replies: 1
    Last Post: 24th June 2011, 12:44
  3. Replies: 1
    Last Post: 31st March 2011, 18:38
  4. Replies: 2
    Last Post: 2nd November 2010, 05:15
  5. Replies: 0
    Last Post: 12th October 2010, 04:14

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.