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

  • Home
  • SEARCH
  • 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 6651953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:04:22+00:00 2026-05-26T01:04:22+00:00

My Makefile looks like this: BIN = bin OBJECTS = object1.o \ object2.o \

  • 0

My Makefile looks like this:

BIN     = bin
OBJECTS = object1.o \
          object2.o \
          object3.o
HDR     = $(OBJECTS:%.o=%.h) header1.h header2.h
MAIN    = main.c

CC      = gcc
CFLAGS  = -Wall -g -std=c99 -fstack-protector-all
LDFLAGS = -lpthread

$(BIN): $(OBJECTS) $(MAIN)
    $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^

%.o: %.c $(HDR)
    $(CC) $(CFLAGS) -c $< -o $@

It seems that the %.o: %.c $(HDR) rule is not used. When invoking with option make -r it says that there’s no rule to make target object.o. The build of each object file should depend on every header file. What am I missing?

Edit: I should mention that when doing echo $(HDR) than it looks like the variable contains the right values:
object1.h object2.h object3.h header1.h header2.h

  • 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-05-26T01:04:23+00:00Added an answer on May 26, 2026 at 1:04 am

    Ok, the given Makefile should work, I had a typo in one of the header file names.

    It’s a pitty, but make doesn’t warn about that. It seems that when a pattern based rule is missing a prerequisite than it’s just ignored. The built-in .o creation rule is used instead.

    Jonathan Leffler’s proposal of ${OBJECTS}: ${HDR} brought that up, because than there’s an error regarding “no rule to make target misspelled.h” – I would have expected that from my rule too.

    So I can just agree to fluffy, it’s better to use auto-generated dependencies instead.

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

Sidebar

Related Questions

My project directory looks like this: /project Makefile main /src main.cpp foo.cpp foo.h bar.cpp
I'm trying to specify rpath in my binary. My makefile looks like this- CC=gcc
I have a Makefile that looks like this CXX = g++ -O2 -Wall all:
I have a Makefile.am file right now that looks like this: lib_LIBRARIES = foo.a
My source and build tree looks like this (see Makefile to put object files
I have a GNU Makefile that looks a bit like this: LIST = item1
I have this makefile: SHELL=/bin/zsh COMPILER=g++ -g COMPILERSO=g++ -a +a1 -b LIBDIR=/Users/romeovs/Desktop/rootex CFLAGS=$(root-config --cflags)
My makefile looks something like this: FOO_OBJECT_FILES := $(OBJDIR)/Foo.cpp.o BAR_OBJECT_FILES := $(OBJDIR)/Bar.cpp.o $(OBJDIR)Bar.c.o ALL_OBJECT_FILES
I am building a console Qt project. Currently, my project file looks like this:
I have a multi module maven project which looks something like: main component_one subcomponent_bob

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.