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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:04:23+00:00 2026-05-28T13:04:23+00:00

I tried the following example program to understand the usage of the makefiles in

  • 0

I tried the following example program to understand the usage of the makefiles in compilation.

main.c

#include<stdio.h>
#include<functions.h>
int main()
{
 print_hello();
 printf("\nThe Factorial is : %d\n",factorial(5));
 return 0;
}

hello.c

#include<stdio.h>
#include<functions.h>
void print_hello()
{
 printf("\nHello world!\n");
}

factorial.c

#include<stdio.h>
#include<functions.h>
void factorial(int n)
{
 if(n!=1){
  return(n*factorial(n-1));
 }
 else
  return 1;
}

functions.h

#include<stdio.h>
void print_hello();
int factorial(int n);

makefile

exec : ./compile

compile : main.o hello.o factorial.o
  gcc -o compile

main.o : main.c functions.h
  gcc -c main.c

hello.o : hello.c functions.h
  gcc -c hello.c

factorial.o : factorial.c functions.h
  gcc -c factorial.c

Error :

cheetah@desktop:~/make_example$ make compile
gcc -c main.c
main.c:2:22: error: functions.h: No such file or directory
make: *** [main.o] Error 1
cheetah@desktop:~/make_example$ 

EDITED:

gcc -c main.c
gcc -c hello.c
gcc -c factorial.c
gcc -o compile
gcc: no input files
make: *** [compile] Error 1

Please help me understand why is it throwing an error as functions.h not found as I have included it in my 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-28T13:04:25+00:00Added an answer on May 28, 2026 at 1:04 pm

    Alternative to changing the source, you can include the current directory for header file lookup using -I option of gcc. In that case your makefile rule where you need the header file will look like as follows (assuming the header file is the current directory):

    main.o : main.c functions.h
      gcc -c main.c -I./
    

    Again as already pointed out, the error you were facing later during linking was due to missing input files in the compile target. For this again there is alternative. You can make use of $^ in the makefile for all you depencies. In which you compile rule will look like:

    compile:main.o hello.o factorial.o
        gcc -o compile $^
    

    See this link for some information regarding makefile macros.
    Side notes:

    1. Guards are missing your header file
    2. There is mismatch in declaration & definition of factorial function.
    3. As already mentioned by Jonathan Leffler be adviced about the prototype of print_hello

    Hope this helps!

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

Sidebar

Related Questions

I'm trying to break into SSE2 and tried the following example program : #include
To clarify my question, let's start off with an example program: #include <stdio.h> #pragma
In the following example (apologies for the length) I have tried to isolate some
I have tried using the obvious method as outlined in the following example but
I tried to execute the following actionscript3 program and I am surprised of the
I tried simple stopwatch program from http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ChronometerDemo.html . The following error is coming R.layout.chronometer
Hi I tried the following example (i don't have im in the global) and
This is my requirement in windows batch file I tried the following Example: f1.txt
I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with
Suppose I've got the following program: namespace ReflectionTest { public class Example { private

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.