我想编写一个 C 代码,例如“test.c”,并从中调用一些 C++ 函数。
我有一个头文件 header.h,其中定义了函数 以及一个包含函数定义的 C++ 文件。
我无法弄清楚编译命令以及如何使用 extern
命令。
有人可以澄清一下吗?
最佳答案
I want to write a C code, say "test.c" call some C++ functions from it.
在标题中尝试类似的内容:
#ifdef __cplusplus
extern "C"
{
#endif
void foo (void);
#ifdef __cplusplus
};
#endif
然后在您的 .cpp 文件中实现 foo()
。确保您的 .cpp 文件还包含 header 。
关于c++ - 在C、VS 2010中包含C++头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10647020/