Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7828399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:20:33+00:00 2026-06-02T10:20:33+00:00

To make it simple, say I have the following folders: ./src/ with many .c

  • 0

To make it simple, say I have the following folders:

  • ./src/ with many .c files
  • ./obj/ with many .obj files
  • ./output/ with my binaries I want to build

My makefile is as follows:

all: init mybin

# init commands
init:
    mkdir obj
    mkdir output

mybin:  project1 project2 project3
    $(CC) src/misc.c ... etc
    $(LK) obj/first.obj obj/second.obj obj/third.obj obj/four.obj obj/five.obj obj/six.obj obj/seven.obj obj/eight.obj obj/nine.obj -o output/myapp.bin

project1: obj/first.obj obj/second.obj obj/third.obj

obj/first.obj: src/first.c
    $(CC) first.c ... etc

obj/second.obj: src/second.c
    $(CC) obj/second.c ... etc

obj/third.obj: src/third.c
    $(CC) obj/third.c ... etc


project2:   obj/four.obj obj/five.obj obj/six.obj

obj/four.obj: src/four.c
    $(CC) four.c ... etc

obj/five.obj: src/five.c
    $(CC) obj/five.c ... etc

obj/six.obj: src/six.c
    $(CC) obj/six.c ... etc


project3:   obj/seven.obj obj/eight.obj obj/nine.obj

obj/seven.obj: src/seven.c
    $(CC) seven.c ... etc

obj/eight.obj: src/eight.c
    $(CC) obj/eight.c ... etc

obj/nine.obj: src/nine.c
    $(CC) obj/nine.c ... etc

The first time I ran make all, everything compiled find. Then I did:

$ touch src/four.c
$ make all
$

But make exits without compiling anything. I guess it did not detect that one of the .c files had changed, however I don’t see what’s wrong with my dependencies.

What I expected:
touching src/four.c should have marked obj/four.obj obsolete, and project2 aswell, hence marking mybin obsolete too. This chain should trigger a new compilation of src/four.c to obj/four.obj and then a new linkage of the whole project.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:20:35+00:00Added an answer on June 2, 2026 at 10:20 am

    Did you specify the output file of compilation (likely the -o option)? By default (for most toolchains), compiling a .c file produces an .o file, not an .obj one.

    UPD.

    To get Make updating targets when some prerequisites change you have to provide an exact dependencies between files as far as Make use timestamps to determine whether a file has been changed.

    That is, all and init could remain as so-called .PHONY targets, but it is a good practice to make the rest targets to be files.

    OUT_DIR := ./output
    SRC_DIR := ./src
    OBJ_DIR := ./obj
    
    MYBIN := $(OUT_DIR)/myapp.bin
    
    OBJS := $(addprefix $(OBJ_DIR)/, \
        first.obj \
        second.obj \
        third.obj \
        four.obj \
        five.obj \
        six.obj \
        seven.obj \
        eight.obj \
        nine.obj)
    
    .PHONY : all mkdir-output mkdir-obj
    all : $(MYBIN)
    
    mkdir-output :
        @mkdir -p $(OUT_DIR)
    
    mkdir-obj :
        @mkdir -p $(OBJ_DIR)
    
    $(MYBIN) : $(OBJS) | mkdir-output
        $(LK) $^ -o $@
    
    $(OBJS) : | mkdir-out
    $(OBJS) : $(OBJ_DIR)/%.obj : $(SRC_DIR)/%.c
        $(CC) $< -object=$@ $(CC_OPT)
    

    The last rule is GNU Make’s static pattern rule. And the mkdir-xxx prerequisites after a pipe sign | are order-only ones.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To make this example as simple as possible, let's say I have the following
Let's say I want to make a simple project tracking system. A manager can
Let's say I have a collection of PDF files with the following paths: /some/path/pdfs/birds/duck.pdf
Let's say we have the following mega-simple Python script: print Initializing.... a=10 print Variable
Say I have a simple table, named content with the following fields: id ,
I have been trying to make a simple web service and have been following
Basically I want to make simple toggle program (that will be mapped to some
Trying to make simple minesweeper game in python, but have one problem. I have
I need information about making installation packages for Linux. I want to make simple
We have following problem. Developers frequently need to make small changes to our web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.