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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:49:46+00:00 2026-05-31T01:49:46+00:00

I have a pre-requisite that I need to declare for a target that needs

  • 0

I have a pre-requisite that I need to declare for a target that needs to always run before I try to build the target. It doesn’t actually generate a file. The problem is, if I declare it as the first dependency of the target itself, then the phony dependency winds up in $^ and confuses a subsequent step of linking.

Here is an example:

    .PHONY: start
    sample-prog-1 : start sample-prog-1.o

Elsewhere I have a rule for building an executable from the object file:

%: %.o
        echo "Building executable $@";$(CC) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ $(LDFLAGS_$@)

Problem is, “start” is a phony target, so it doesn’t exist, but the link stage is being called with “start” as one of the object files, so the build process croaks!

I found a work-around, which is simply to strip out “start” from the list of object files:

%: %.o
    echo "Building executable $@";$(CC) $(LDFLAGS) $(shell echo "$^" | sed s/start//g) $(LOADLIBES) $(LDLIBS) -o $@ $(LDFLAGS_$@)

But in addition to seeming very hacky and ugly, it also means I can’t have any source files that have “start” in them. I also wind up always re-building sample-prog-1, as “begin” always winds up being remade.

This just seems like the wrong solution, but I’m at a loss as to what the “right” way to do this is. I’m thinking I should do something where I factor out the executable with something like this:

    sample-prog-1 : sample-prog-1.o
    do_sample-prog-1 : start sample-prog-1

But this is unintuitive, because now if I want to build a given target i have to remember to prepend or append some other string to that target name so that the start code will be run before the executable is built.

  • 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-31T01:49:48+00:00Added an answer on May 31, 2026 at 1:49 am

    You might consider an order-only prerequisite:

    sample-prog-1 : sample-prog-1.o | start
    

    Amongst other things, order-only prerequisites don’t appear in $^.

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

Sidebar

Related Questions

Suppose I have an MSI, that has .NET Framework as a pre-requisite. I know
I have a couple of pre-existing applications which I need to run in one
I have a project that comprises pre-build Dll modules, built some time in the
I have a pre tag within my page that contains quite a bit of
I have a form that I pre-populate with test data though jQuery. $('INPUT[name=subscription.FirstName]').val('Jef'); but
I have a need to run some automation tasks in a web browser control
I have a lot of pre-existing BMPs (and our clients have pre-existing bmps as
I have the following couple of C pre-processor macros for creating test functions: //
I have never seen the usecase for pre-increment and post-increment in actual code. The
Suppose you have a method with some pre and post-conditions. Is it ok to

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.