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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:56:55+00:00 2026-05-28T14:56:55+00:00

This is a sample program i was trying to compile this below c program

  • 0

This is a sample program i was trying to compile this below c program to know about the
make file.

main.c

#include<stdio.h>
#include "reciprocal.h"
int main(int argc,char **argv){
 int i;
 i=atoi(argv[1]);
 printf("The Reciprocal of %d is %f\n ",i,reciprocal(i));
 return 0;
}

reciprocal.c

#include<stdio.h>
#include<assert.h>
#include "reciprocal.h"
double reciprocal(int i){
assert(i!=0);
return 1.0/i;
}

reciprocal.h

#include<stdio.h>
#ifdef __cplusplus 
extern "C"{
#endif
extern double reciprocal(int i);
#ifdef __cplusplus
}   
#endif 

makefile

CFLAGS:=-o2
reciprocal: reciprocal.o main.o
        gcc $(CFLAGS) -o reciprocal.o main.o
main.o: main.c reciprocal.h
        gcc $(CFLAGS) -c main.c -I ../include 
reciprocal.o: reciprocal.c reciprocal.h
        gcc $(CFLAGS) -c reciprocal.c -I ../include 
clean: 
        rm -f *.o reciprocal

when compiled as below it throws an error.

% make

gcc -o2 -c reciprocal.c -I ../include gcc -o2 -c main.c -I ../include
gcc -o2 -o reciprocal.o main.o main.o: In function main':
main.c:(.text+0x25): undefined reference to
reciprocal’ collect2: ld
returned 1 exit status make: * [reciprocal] Error 1

Please help me understand what is the reason for this error.

  • 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-28T14:56:56+00:00Added an answer on May 28, 2026 at 2:56 pm

    Change your makefile:

    reciprocal: reciprocal.o main.o
            gcc $(CFLAGS) -o reciprocal reciprocal.o main.o
                             ^^^^^^^^^^
    

    Alternatively:

    reciprocal: reciprocal.o main.o
            gcc $(CFLAGS) -o $@ $^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I compile this program: #include <stdio.h> int main() { printf(Hello World!); return 0; }
This problem arose when trying to compile a sample program from Stroustrup's Programming Principles
I'm trying to compile a simple program, with #include <gtkmm.h> The path to gtkmm.h
I'm trying to get this simple program to work on windows, but it crashes:
I'm having trouble getting a sample program to link correctly (in this case against
in this sample method/message: -(void) setNumerator:(int) n { numerator = n; } What does
I am just trying to compile and run a very simple test program, but
I'm trying to build the XPCOM component available here: http://mxr.mozilla.org/mozilla-central/source/xpcom/sample/ I tried to compile
I am trying to compile simple program under linux. These are the set of
hi am trying to compile a simple program in boost library but i keep

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.