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

  • Home
  • SEARCH
  • 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 3664422
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:38:40+00:00 2026-05-19T01:38:40+00:00

I have one set of source files from which I need to generate multiple

  • 0

I have one set of source files from which I need to generate multiple variants of an executable. For example I need to generate app1.elf, app2.elf, app3.elf from the same main.c and comm.c. The difference between each of the apps is a node address, a parameter that is passed down in the invocation of gcc. i.e.:

gcc -DNODE=1 -oapp1.elf main.c 
gcc -DNODE=2 -oapp2.elf main.c 
gcc -DNODE=3 -oapp3.elf main.c 

Let’s assume that I have the following files:

  • src/main.c
  • src/comm.c

When I run the Makefile as so:

make all_nodes

make only builds app1.elf with the following output:

Built app1
Built app2
Built app3

FAIL!
The output seems to suggest that it worked, however it only generates one executable, namely app1.elf. Anybody care to point out what I’m doing wrong?

To further explain my Makefile, I’ve created a cleanobjs target to clean out the objects in the ./obj subdirectory. This is my attempt at having ‘make’ rebuild the obj files with the new node address, but it fails. Am I using ‘make’ in a way it wasn’t intended to be used? I know I can also create a batch file to run make (something I’ve done sucessfully) but I’d like to know what I’m doing wrong. My Makefile is below:

obj/%.o: src/%.c
    gcc -DNODE=$(NODE) -o$@ $<

app.elf : ./obj/main.o ./obj/comm.o
    gcc -oapp$(NODE).elf main.o comm.o

node1 : NODE=1
node1 : cleanobj app.elf
    @echo 'Built app1'

node2 : NODE=2
node2 : cleanobj app.elf
    @echo 'Built app2'

node3 : NODE=3
node3 : cleanobj app.elf
    @echo 'Built app3'

all_nodes : node1 node2 node3

cleanobj :
    rm -rf obj/main.o obj/comm.o

.PHONY : cleanobj
  • 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-19T01:38:41+00:00Added an answer on May 19, 2026 at 1:38 am

    This is what I would do:

    SRC     = src/main.c
    OBJ     = $(patsubst src%,obj$(VERSION)%,$(patsubst %.c,%.o,$(SRC)))
    
    C_FLAGS = -DNODE=$(VERSION)
    
    
    all:    app.1 app.2 app.3
    
    #
    # For each application just call make with VERSION set correctly    
    app.%:  dir.%
        $(MAKE) VERSION=$* app$*.elf
    
    #
    # Build each applications objects into a seprate directory
    # So we need to make sure the obj directory exists.    
    dir.%:
        @- if ! test -e obj$*; then mkdir obj$*; fi
    
    app%.elf:   $(OBJ)
        $(CC) -o$@ $(C_FLAGS) $(OBJ)
    
    
    obj$(VERSION)/%.o:  src/%.c
        $(CC) -c -o obj$(VERSION)/$*.o $(C_FLAGS) $<
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table that saves comments for a varied set of content types.
I have one class that needs to grab an attribute that is set in
I have a table where one of the left column shrinks when I set
I have a set of five boolean values. If more than one of these
I have one field that I need to sum lets say named items However
I have one std::list<> container and these threads: One writer thread which adds elements
I have one thread that writes results into a Queue. In another thread (GUI),
I have one hibernate sequence, that generates all sequence-numbers in my app. When I
I have one text input and one button (see below). How can I use
I have one website on my server, and my IIS Worker Process is using

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.