Monday, December 19, 2011

How to call C functions from CPP file

Reference: How to call c function from CPP file

For example

filea.c
int apb(int a, int b)
{
return a+b;
}
filea.h
int apb(int a, int b);
fileb.cpp
#include "filea.h"
int main(void)
{
 return apb(5,1);
}
compiler tells me error:
Error: L6218E: Undefined symbol apb(int, int) (referred from fileb.o).
Solution:
extern "C"
{
#include "filea.h"
}

int main(void)
{
 return apb(5,1);
}

No comments: