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 8863523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:59:58+00:00 2026-06-14T15:59:58+00:00

my Makefile: CC=cc INC=-I. CFLAGS=-g -DDEBUG -std=gnu99 -DSFHASH -DDOMAIN LDFLAGS=-ldl OBJS=*.o OBJDIR=.obj BINDIR=.obj LIBDIR=.obj

  • 0

my Makefile:

CC=cc
INC=-I.
CFLAGS=-g  -DDEBUG -std=gnu99 -DSFHASH -DDOMAIN
LDFLAGS=-ldl
OBJS=*.o
OBJDIR=.obj
BINDIR=.obj
LIBDIR=.obj

%.o: %.c
        $(CC) $(INC) $(CFLAGS) -DSFHASH -o $(OBJDIR)/$@ -c $<


VPATH = .obj
#vpath %.o $(OBJDIR)

hashtest: hashfuncs.o hast.o scanners.o parseargs.o
        $(CC) -rdynamic -o $(BINDIR)/$@ $^ $(LDFLAGS)

clean:
        @rm -f $(OBJDIR)/$(OBJS) $(BINDIR)/hashtest

using it for the first time: make does not rewrite gcc’s input file paths:

@delphi# make clean
@delphi# make
cc -I. -g  -DDEBUG -std=gnu99 -DSFHASH -DDOMAIN -DSFHASH -o .obj/hashfuncs.o -c hashfuncs.c
cc -I. -g  -DDEBUG -std=gnu99 -DSFHASH -DDOMAIN -DSFHASH -o .obj/hast.o -c hast.c
cc -I. -g  -DDEBUG -std=gnu99 -DSFHASH -DDOMAIN -DSFHASH -o .obj/scanners.o -c scanners.c
cc -I. -g  -DDEBUG -std=gnu99 -DSFHASH -DDOMAIN -DSFHASH -o .obj/parseargs.o -c parseargs.c
cc -rdynamic -o .obj/hashtest hashfuncs.o hast.o scanners.o parseargs.o -ldl
cc: error: hashfuncs.o: No such file or directory
cc: error: hast.o: No such file or directory
cc: error: scanners.o: No such file or directory
cc: error: parseargs.o: No such file or directory
make: *** [hashtest] Error 1

using it second time in a row, it does:

@delphi# make
cc -rdynamic -o .obj/hashtest .obj/hashfuncs.o .obj/hast.o .obj/scanners.o .obj/parseargs.o -ldl
@delphi# 

GNU Make manual says:

The value of the make variable VPATH specifies a list of directories
that make should search. Most often, the directories are expected to
contain prerequisite files that are not in the current directory;
however, make uses VPATH as a search list for both prerequisites and
*targets of rules*.

I would understand if VPATH is a set-once-at-startup-typeof-variable but it’s not. The fact that the target’s dependencies generated at runtime are properly looked up says so.

What’s up with that? Why is make correctly rewriting input file paths for gcc only the second time?

  • 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-14T15:59:59+00:00Added an answer on June 14, 2026 at 3:59 pm

    The explanation of this behavior can be found in section 3.7 of the GNU Make manual:

    3.7 How make Reads a Makefile

    GNU make does its work in two distinct phases. During the first phase it reads all the makefiles,
    included makefiles, etc. and internalizes all the variables and their values, implicit and
    explicit rules, and constructs a dependency graph of all the targets and their prerequisites.

    During the second phase, make uses these internal structures to determine what targets will
    need to be rebuilt and to invoke the rules necessary to do so.

    When you run the make for the first time, the prerequisites in the .obj directory do not yet exist. That means that they will not be part of the dependency graph as created during the first phase. Consequently, these prerequisites are not used during the second phase when executing the rule to create hashtest — even though they exist by that time due to rules previously executed during the second phase.

    When you run make for the second time, these prerequisites do exist and are found and included in the dependency graph by virtue of the VPATH setting.

    Please note that the expression in VPATH is only a search path, nothing more. It can contain multiple directory names, separated by a colon. make will search in that search path for prerequisites and targets while constructing the dependency graph during the first phase. If it finds a particular target in a directory in that search list, then that target is added to the dependency graph as an existing file, that might or might not be out of date.

    You seem to expect that make adds a subdirectory from VPATH to a target, even if that target does not exist in that subdirectory and needs to be created. That is not how it works — how would make deal with multiple directories in VPATH in that case?

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

Sidebar

Related Questions

I am reading a Makefile from someone else as follows. LDFLAGS=-lm -ljpeg -lpng ifeq
gcc 4.4.4 I have the following Makefile OBJECT_FILES = brd.o logger.o test_brd.o CFLAGS =
Consider the following makefile: .SUFFIXES: SRC:=../Src OBJ:=../Obj # Sources SOURCES := $(SRC)/App/a.c $(SRC)/App/b.c $(SRC)/App/c.c
Suppose in my makefile I have program_INCLUDE_DIRS += ../inc CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir)) Now
My makefile is below Also, I would appreciate it if you told me how
Is makefile an advanced problem or a general problem for a programmer? For a
I have a big makefile that I have configured with several phony targets. One
I'm creating a Makefile for a project. I have the following structure of Makefiles:
I have a gnu makefile template that has served me well, but when I
I have a makefile for compiling Arduino programs . I need to add some

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.