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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:35:00+00:00 2026-06-12T21:35:00+00:00

Hello I need to create a makefile for 2 separated cpp programs that are

  • 0

Hello I need to create a makefile for 2 separated cpp programs that are in one directory. I have got this code, but it’s not working correctly. The .o files do not get created.Thank you

OBJS = a b
EXEC = first_run second_run

#------ constant definitions

ALL_OBJ = $(OBJS:%=%.o)

all: $(EXEC)

clean:
    $(RM) $(EXEC) $(OBJS) $(ALL_OBJ); make all

CC = g++

DO_OBJS = $(CC) -cpp -o $@.o $@.cpp; touch $@
DO_EXEC = $(CC) -s -o $@ $(ALL_OBJ)

#------ now compile

$(OBJS):    $(@:%=%.o)
        $(DO_OBJS)

$(EXEC):    $(OBJS)
        $(DO_EXEC)
  • 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-12T21:35:01+00:00Added an answer on June 12, 2026 at 9:35 pm

    There are a couple of problems with your file, but the major problem seems to be that you try to link both source files to a single executable. You have to list each program and its dependencies on its own.

    Try instead this simple Makefile:

    SOURCES = a.cpp b.cpp
    OBJECTS = $(SOURCES:%.cpp=%.o)
    TARGETS = first_run second_run
    
    LD = g++
    CXX = g++
    CXXFLAGS = -Wall
    
    all: $(TARGETS)
    
    # Special rule that tells `make` that the `clean` target isn't really
    # a file that can be made
    .PHONY: clean
    
    clean:
        -rm -f $(OBJECTS)
        -rm -f $(TARGETS)
    
    # The target `first_run` depends on the `a.o` object file
    # It's this rule that links the first program
    first_run: a.o
        $(LD) -o $@ $<
    
    # The target `second_run` depends on the `b.o` object file
    # It's this rule that links the second program
    second_run: b.o
        $(LD) -o $@ $<
    
    # Tells `make` that each file ending in `.o` depends on a similar
    # named file but ending in `.cpp`
    # It's this rule that makes the object files    
    .o.cpp:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody help me to fix this code, I really need it, but have
Hello all, I need to create a query for house search, that would match
I need to create a program that creates another program but not a compiler
I have a dynamic application that need to create a window interface with checkbox.
I have a string object hello world I need to create an xml file
Hello i need to create a progressView when i load data from my webservice.
Hello ! I need to create a report like the attachment shows with Jasper
Hello I need to have multiple language support of my django admin application.I can
Hello I need to do something like this: UPDATE tbl SET pozn=CONCAT(pozn, '+attach_str+') WHERE
Possible Duplicate: Creating makefile Hello, I am trying to create the makefiles and configure

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.