我有一個程序,我不得不將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'。 –