test.cpp
#include "test.h"
int test1(int i)
{
return i*2;
}
Res test2(int i, int k)
{
return Res(i*2,k*2);
}test.h
struct Res
{
int i,k;
Res(int ii,int kk):i(ii),k(kk){}
};
int test1(int i);
Res test2(int i, int k);test_cpp.cpp
#include "test.h"
#include "test_cpp.h"
extern "C" int wr_test1(int i)
{
return test1(i);
}
extern "C" ResC wr_test2(int i, int k)
{
Res r = test2(i,k);
ResC rr;
rr.i = r.i;
rr.k = r.k;
return rr;
}test_cpp.h
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _Res
{
int i,k;
} ResC;
int wr_test1(int i);
ResC wr_test2(int i, int k);
#ifdef __cplusplus
}
#endifmain.c
#include "test_cpp.h"
#include "stdio.h"
int main()
{
ResC c;
printf("%d\n",wr_test1(2));
c = wr_test2(2,4);
printf("%d,%d\n",c.i,c.k);
return 0;
}Makefile
CFLAGS = -g -Wall
LIBS =
all:
g++ -c $(CFLAGS) test_cpp.cpp test.cpp
g++ test_cpp.o test.o $(CFLAGS) main.c


0 коммент.:
Отправить комментарий