S
Sameer
Hello Groups,
I am facing this linking problem while using a c++ function in a C code.
I get this error....
gcc -o a.out cpp.o test.o
test.o(.text+0x29):test.c: undefined reference to `add'
Kindly tell me what is the problem.
Regards,
file "cpp.h" contains
#if __cplusplus
extern "C" {
#endif
extern int add(int a, int b);
#if __cplusplus
}
#endif
file "test.c" contains
#include<stdio.h>
#include"cpp.h"
main()
{
int a=1, b=2 ,c;
c=add(a,b);
printf("%d\n", c);
}
file "cpp.cc" contains
#include<iostream>
using namespace std;
int add(int a, int b)
{
int c;
c=a+b;
return c;
}
Makefile
a.out: cpp.o test.o
gcc -o a.out cpp.o test.o
test.o: test.c cpp.h
gcc -c test.c
cpp.o: cpp.cc
g++ -c cpp.cc
I am facing this linking problem while using a c++ function in a C code.
I get this error....
gcc -o a.out cpp.o test.o
test.o(.text+0x29):test.c: undefined reference to `add'
Kindly tell me what is the problem.
Regards,
file "cpp.h" contains
#if __cplusplus
extern "C" {
#endif
extern int add(int a, int b);
#if __cplusplus
}
#endif
file "test.c" contains
#include<stdio.h>
#include"cpp.h"
main()
{
int a=1, b=2 ,c;
c=add(a,b);
printf("%d\n", c);
}
file "cpp.cc" contains
#include<iostream>
using namespace std;
int add(int a, int b)
{
int c;
c=a+b;
return c;
}
Makefile
a.out: cpp.o test.o
gcc -o a.out cpp.o test.o
test.o: test.c cpp.h
gcc -c test.c
cpp.o: cpp.cc
g++ -c cpp.cc