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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:17:54+00:00 2026-05-27T20:17:54+00:00

I was wondering … When you make a change to either file1.c or file2.c

  • 0

I was wondering …

When you make a change to either file1.c or file2.c or file1.h, the following makefile recompiles only what’s needed (which is nice)

# Link to executable
result: file1.o file2.o
    gcc file1.o file2.o -o result23

# Assemble to .o object files
file1.o:    file1.s
    gcc -c dist/file1.s

file2.o:    file2.s
    gcc -c dist/file2.s

# Compile to .s assembly files
file1.s:    file1.c
    gcc -S file1.c

file2.s:    file2.c
    gcc -S file2.c

When I move built object to another directory, however, everything is rebuilt at all times, regardless whether only 1 file’s content was changed.

# Link to executable
result: file1.o file2.o
    gcc file1.o file2.o -o result23

# Assemble to .o object files
file1.o:    file1.s
    gcc -c dist/file1.s
    mv file1.o dist

file2.o:    file2.s
    gcc -c dist/file2.s
    mv file2.o dist

# Compile to .s assembly files
file1.s:    file1.c
    gcc -S file1.c
    mv file1.s dist

file2.s:    file2.c
    gcc -S file2.c
    mv file2.s dist

It seems that this is happening because make does not know where the .o files are in it’s environment.

With this a few questions:

  • Can make have access to environment variables? If so, could you provide an example?
  • Can make be made aware of incremental builds when distribution directory is different from current directory?
  • 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-27T20:17:54+00:00Added an answer on May 27, 2026 at 8:17 pm

    To fix your build you’ll need to do something like this:

    # Link to executable
    result: dist/file1.o dist/file2.o
        gcc dist/file1.o dist/file2.o -o result
    
    # Assemble to .o object files in main directory
    dist/file1.o:    dist/file1.s
        gcc -c dist/file1.s -o dist/file1.o
    
    dist/file2.o:    dist/file2.s
        gcc -c dist/file2.s -o dist/file2.o
    
    # Compile to .s assembly files
    dist/file1.s:    file1.c
        gcc -S file1.c -o dist/file1.s
    
    dist/file2.s:    file2.c
        gcc -S file2.c -o dist/file2.s
    

    You can certainly use environment variables in make too.. though I’m not sure how that relates to the core of your question: Just use something like this, set BUILDDIR and OBJDIR and have a makefile like this:

    $(BUILDDIR)/foo : $(OBJDIR)/bar.o
       g++ $(OBJDIR)/bar.o -o $(BUILDDIR)/foo
    

    Though you can make this (and my fixed makefile too) nicer using automatic variables:

    $(BUILDDIR)/foo : $(OBJDIR)/bar.o
      g++ $? -o $@
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering what would be the most efficient way to do the following. Game play.
Wondering if it's possible to change a value returned from a queryset before sending
Wondering what the difference is between the following: Case 1: Base Class public void
Wondering what the best way to make this more efficient, perhaps with jQuery. I
Wondering if there is a way to change the left css value of this
Wondering if anyone out there can shed some light on why the following regular
Wondering if there is any php script out there which takes an sql db
Wondering if it is a good or bad ideal to make use of Hibernate
Wondering what the point of if (self = [super ... in the following code
wondering if there's any way to make it so that a list I have

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.