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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:18:31+00:00 2026-05-29T05:18:31+00:00

When I use make, it says gcc -I./header -c -g main.c gcc: error: main.c:

  • 0

When I use make, it says

gcc -I./header -c -g main.c
gcc: error: main.c: No such file or directory

My makefile is here:

vpath %.c ./src
vpath %.h ./header

CC = gcc
FLAG = -I./header -c -g
objects = main.o a.o b.o

app: ${objects}
    ${CC} -o app ${objects}

main.o: main.c command.h
    ${CC} ${FLAG} main.c

a.o: a.c command.h
    ${CC} ${FLAG} a.c

b.o: b.c command.h
    ${CC} ${FLAG} b.c

clean: 
    -rm *.o app

.PHONY: clean

and files are stored like this:

.
|-- header
|   `-- command.h
|-- Makefile
`-- src
    |-- a.c
    |-- b.c
    `-- main.c

What’s wrong with the Makefile?

  • 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-29T05:18:33+00:00Added an answer on May 29, 2026 at 5:18 am

    You should use automatic variables instead of hard coded values for file names in recipes:

    main.o: main.c command.h
        ${CC} ${FLAG} $<
    
    ...
    

    This allows Make to insert the right file names found in vpath:

    When a prerequisite is found in another directory through directory search, this cannot change the recipe of the rule; they will execute as written. Therefore, you must write the recipe with care so that it will look for the prerequisite in the directory where make finds it.

    This is done with the automatic variables such as $^ (see Automatic Variables). For instance, the value of $^ is a list of all the prerequisites of the rule, including the names of the directories in which they were found, and the value of $@ is the target.

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

Sidebar

Related Questions

I've stumbled on a make file Makefile.am and I tried to use make -f
This is what it says: You can use an incrementer to make a number
We use Make to compile our product, which includes, C, C++, Java and a
When I use make command, like make mica2, in TinyOS. The following problem will
A sysadmin teacher told me one day that I should learn to use make
I make use of the Mydac components by devart (corelab) to access MySql from
We make use of views and panels quite often in Drupal and a lot
I make use of generic views and I am attempting to query my MySQL
We use GNU Make for our system. At the end of our makefiles, we
I frequently make use of Request.QueryString[] variables. In my Page_load I often do things

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.