Not sure whether its the best way to do it but generally i prefer this way,
Create a ".cpp" file say test.cpp, compile it with -C
option and generate an '.o' file
Then, create one .c file declare and Call that cpp function from here, and compile it with g++
Below is the example,
**
test.cpp
**
#include<iostream>
using namespace std;
int sum(int a,int b)
{
return a+b;
}
**
test2.c
**
#include<stdio.h>
int sum(int,int);
main()
{
printf("sum = %d\n",sum(10,20));
}
**
Do below stepst to compile and run
**,
g++ -C test.cpp -o test.o
g++ test2.c test.o