我有一个程序,我不得不将C和C++代码融合在一起。我已经在C中定义了一些全局变量,我需要在C和C++文件中访问它们,但无法解决它。下面是我有什么,这在C文件的工作,但不是在每次通话费用:从CPP文件中的C文件访问变量
章
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _COMMON_H_
#define _COMMON_H_
extern char test[100];
#ifdef __cplusplus
}
#endif
抄送
#include <windows.h>
#include <stdio.h>
#include "C.h"
char test[100] = "value";
CPlusPlus.cpp
#include "C.h"
int TestFunction() {
// I need to access variable test here
}
谢谢, 奔
那么,什么不起作用?编译器错误?链接?运行? –
问题是什么? – Nawaz
你错过了'C.h'中的'#endif'。 –