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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:45:50+00:00 2026-05-19T13:45:50+00:00

I have a complicated makefile that seems to relink my libraries and executables every

  • 0

I have a complicated makefile that seems to relink my libraries and executables every time I invoke it. I was able to narrow down the problem into a simple makefile:

 1: all: prog
 2:
 3: .PHONY: prog
 4: prog: prog.exe
 5:
 6: prog.exe: lib prog.o
 7:         touch prog.exe
 8:
 9: prog.o: prog.c
10:         touch prog.o
11:
12: .PHONY: lib
13: lib: lib.so
14:
15: lib.so: lib.o
16:         touch lib.so
17:
18: lib.o: lib.c
19:         touch lib.o
20:
21: .PHONY: clean
22: clean:
23:         rm *.so *.o *.exe

For some reason, this example, prog.exe is created every time. If I replace the lib on line 6 with lib.so then it works. Yet it seems like I should be able to do what I’m attempting here. Is there something fundamental I’m missing?

  • 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-19T13:45:51+00:00Added an answer on May 19, 2026 at 1:45 pm

    From the online GNU make manual:

    A phony target should not be a
    prerequisite of a real target file; if
    it is, its recipe will be run every
    time make goes to update that file. As
    long as a phony target is never a
    prerequisite of a real target, the
    phony target recipe will be executed
    only when the phony target is a
    specified goal (see Arguments to
    Specify the Goals).

    That at least explains what you are seeing. Since prog.exe depends on lib, your phony target for collecting libraries, the lib rule is fired, and hence prog.exe is “out of date”, and gets relinked.

    It looks like you’ll have to be more explicit about your dependencies. Perhaps you would be interested in putting them in a variable to make managing multiple libraries a bit easier? For example:

    LIBS = lib.so
    
    all: libs progs
    
    .PHONY: progs libs clean
    
    progs: prog.exe
    
    prog.exe: $(LIBS) prog.o
        touch prog.exe
    
    # etc.
    libs: $(LIBS)
    
    lib.so: lib.o
        touch lib.so
    
    # and so on
    

    In the above example, I’ve also changed the names of the phony targets to progs and libs, which in my experience are more common. In this case, the libs target is just a convenience for building all the libraries, rather than acting as an actual dependency.

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

Sidebar

Related Questions

Im having a very strange problem, i have a complicated view that returns incorrect
I have some complicated C++ code but the problem narrows down to doing a
I have a complicated problem and I hope to explain it clearly possible... I
I have a complicated MySQL query which takes a lot of time, selecting from
I have a complicated report that I need to draw with GDI+ (I don't
I have this complicated slider that utilizes tons of animation. I'm trying to find
I have some complicated, problem to be solved. Now I need to write such
I have a complicated problem, and I need help. I have a base case,
I have a fairly complicated installer that I'm writing in Wix that has a
I have a complicated Google Visual API chart that I need to add 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.