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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:52:04+00:00 2026-06-12T15:52:04+00:00

I am currently learning C and now I am upto the tutorial where I

  • 0

I am currently learning C and now I am upto the tutorial where I need to write the Makefile but I am difficulty writing a Makefile for multiple sources. Can someone tell me how I can correct my code for the Makefile for multiple sources? All of the files are in the same directory and there are a total of 3 C source files as indicated by filename1/2/3 etc. I am trying to build 3 separate programs with 3 source files in a single makefile

 OPT = -O4              

all: filename1

filename1: filename1.o 
    gcc $(OPT) -o filename1 filename1.o

filename1.o: filename1.c
    gcc $(OPT) -c filename1.c

filename2: filename2.o 
    gcc $(OPT) -o filename2 filename2.o

filename2.o: filename2.c
    gcc $(OPT) -c filename2.c   

filename3: filename3.o 
    gcc $(OPT) -o filename3 filename3.o

filename3.o: filename3.c
    gcc $(OPT) -c filename3.c       
clean:
    rm -f *.o
    rm -f filename1
    rm -f filename2
    rm -f filename3

Or is my code fine for what I want it to do?

  • 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-12T15:52:05+00:00Added an answer on June 12, 2026 at 3:52 pm

    Okay, so there doesn’t appear to be anything wrong with the makefile, given that you’re making three different programs. It should work.

    Some suggestions for making it a little more usable:

    1) Declare the “all” and “clean” targets to be phony. This will prevent Make from trying to make files called “all” and “clean”.

    .PHONY: all clean
    

    2) You probably want your “all” target to build all three of your programs, not just one, so change that to:

    all: filename1 filename2 filename3
    

    3) If you end up using this to make more than three programs, and they all share similar build procedures, you can collapse your rules into a smaller set using pattern matches. See Martin Beckett’s answer for an example. But, that’s not necessary.

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

Sidebar

Related Questions

I am currently learning the zsh and now I wanted to use strftime but
I am learning C++ in school now. Currently using C++ with codeblocks on my
I am currently learning backbone.js via a screencast tutorial, somewhere along the way, my
I'm currently learning Zend Framework and now I am looking for a way to
I'm currently learning traditional ASP.NET, but then there is a lot of buzz around
I am currently learning Haskell. I am trying to write a function which given
I'm currently learning working with certificates and now I'm curious, if it is possible
I am currently learning c# and reading a few books. I can do quite
I'm studying C# right now and currently learning threading. Here is a simple example
I'm currently learning Java by developing a tool for creating and filling out multiple-choice-forms

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.