-2

I am new to C programming. Please see the error in the snapshot below. I am getting undefined reference to 'square'. But when I write the function square inside the main.c file it's working!!GREAT
But I wonder what could be the reason. Please help!!
Forgive if its stupid.

This is main.c

#include "square.h"
int main()
{
    int x=4,y;
    y=square(x);
    printf("y is %d\n",y);
    return 0;
}

Now square.h

#ifndef SQUARE_H_INCLUDED
#define SQUARE_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
int square(int num);
#endif

Now square.c

int square(int num)
{
    int result;
    result=num*num;
    return result;
}

I have edited the code as well.{I am using code blocks IDE}

JaalaP
  • 1
  • 1
  • 3
    Please post code as text, not pictures of text, and not links to pictures of text. Also, what IDE are you using and how is it configured to compile? – dbush Oct 13 '17 at 13:14
  • Sorry, I am using CodeBlocks IDE. Forgive me as I am new. – JaalaP Oct 13 '17 at 13:16
  • Being new is no excuse. You were provided with more than enough information about using the site _when you joined_, but you chose to ignore it. This is what happens when you do that. – dandan78 Oct 13 '17 at 13:20
  • You didn't show us the command you used to compile and (in particular) link the executable. Could you please [edit] to demonstrate that you don't have the same problem as in the marked duplicate question? – Toby Speight Oct 16 '17 at 13:34

1 Answers1

0

main.c has no refernce to square implementation. Either add square.h file and include it both in square.c and im main.c or write squre implemenation in main.c

Dror Moyal
  • 398
  • 3
  • 11