23,215
社区成员




cppfunc.cpp:
#include "cppfunc.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
void func1()
{
...
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
cppfunc.h:
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
extern void func1();
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
//然后在c文件中直接include 该头文件
cfile.c
#include "cppfunc.h"
void main(argc, argv)
{
func1();//这里直接调用即可
}
//C++头文件 cppExample.h
#ifndef CPP_EXAMPLE_H
#define CPP_EXAMPLE_H
extern "C" int add( int x, int y );
#endif
//C++实现文件 cppExample.cpp
#include "cppExample.h"
int add( int x, int y )
{
return x + y;
}
/* C实现文件 cFile.c
/* 这样会编译出错:#include "cExample.h" */
extern int add( int x, int y );
int main( int argc, char* argv[] )
{
add( 2, 3 );
return 0;
}
本文来自CSDN博客:
http://blog.csdn.net/lbzhao_28/archive/2008/10/27/3159598.aspx