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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:09:10+00:00 2026-06-07T00:09:10+00:00

I have the files main.c , version1.c , version2.c and header.h version1.c and version2.c

  • 0

I have the files main.c, version1.c, version2.c and header.h

version1.c and version2.c are two different implementations of the same header file (header.h), and this header file is used by main.c.

Now, I want to

$ make v1
cc -c main.c
cc -c version1.c
cc -o prog main.o version1.o

or

$ make v2
cc -c main.c
cc -c version2.c
cc -o prog main.o version2.o

depending on which version of code I’m using.

I tried Conditionally appending to a variable inside a Makefile target and wrote

.PHONY: v1 v2
OBJ = main.o
v1: OBJ += version1.o
v2: OBJ += version2.o
v1 v2: prog
prog: $(OBJ)
     cc -o prog $(OBJ)
%.o: %.c header.h
     cc -c $<

But this quite simply does not work:

$ make v1
cc -c main.c
cc -o prog main.o version1.o
cc: version1.o: No such file or directory
make: *** [prog] Error 1

it seems that make evaluates $(OBJ) before the append when it appears in the dependency list, but after it when it appears in the command list.

Is this a bug in make? Or am I just doing it wrong? How do I do this correctly?

  • 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-07T00:09:11+00:00Added an answer on June 7, 2026 at 12:09 am

    The target-specific modification of the variable (v1: OBJ += version1.o) applies in the body of the rule, not in the prerequisite list. Here’s how I’d do it:

    .PHONY: v1 v2
    v1: version1.o
    v2: version2.o
    v1 v2: main.o
        cc -o prog $^
    
    %.o: %.c header.h
        cc -c $<
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two files in my src/main/resources and I want one file's body to
I have two frames in different files (main frame and settings frame), and I'd
I have a two JavaScript files: Main.js Pmt.js I'm also using thick box (Ajax
Here I am trying to implement the jQuery I have two main files one
I have two files 1 - index.php 2 - main.php index.php call to main.php
I have a main activity with this layout file: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I am trying to extract the mp3 header from a file. This is different
I have a second .nib file that is a localized version of the main
I have 3 files main.cpp a.h b.h main.cpp includes both a.h and b.h b.h
I have a project in which i have the following files main.wxs - directory

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.