Hi... I converted a basic adding program from matlab .m function file into .c & .h file. When i try to include the header file function "add" into my main function in dev-c++ --- [Linker error] undefined reference to `add' is the error message on compilation.
Here is my code
Main function code:

#include "add.h"
#include <conio.h>
   real_T x,y,z;
    printf("Enter two numbers to add\n");
    y =  add(x,z);
    printf("Sum of entered numbers = %lf\n",y);
    //return 0;

add.h Header file code

#ifndef __ADD_H__
#define __ADD_H__
/* Include files */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "rtwtypes.h"
#include "add_types.h"

/* Type Definitions */

/* Named Constants */

/* Variable Declarations */

/* Variable Definitions */

/* Function Declarations */
//extern real_T add(real_T x, real_T z);
real_T add(real_T x, real_T z);
/* End of code generation (add.h) */

FYI : rtwtypes.h has got all the data type defined using typedef....! for double its **real_T **....!

Thanks for your time and valuable suggestions!

real_T add(real_T x, real_T z);

And where is add() defined? The error is saying that you have a declaration for the function, but no definition exists and therefore it cannot be called.

As i mentioned earlier -- i tried n used matlab to generate these c files ...! I have got add.c (source) / add.h , rtwtypes.h (all datat types are typedefined), add_types.h , add_intialize.h , add_terminate.h ...!
I think including add.h will be more enough to call the add() function...!
anyway here is the source add.c which i got frm matlab....


#include "rt_nonfinite.h"
#include "add.h"

real_T add(real_T x, real_T z)
  return x + z;
This article has been dead for over six months. Start a new discussion instead.