There is a very big C file, which defined a lot of strings and used locally. I would like to do access these strings from a C++ file, but using extern "C" does not help.
The C file look like this: data.c
#include <stdio.h>
static char* str = "string\n";
void p() {
printf(str);
}
and the c++ file look like this:
#include <iostream>
extern "C" {
extern char* str;
extern void p();
};
int main(int argc, char* argv[]) {
p();
std::cout << str;
return 0;
}
I am using VS2013, the compile gives error
error LNK2001: unresolved external symbol _str
fatal error LNK1120: 1 unresolved externals
Calling the functions defined in C file has no problem.
Is it even possible to access the variables in C from C++? And how to do it correctly?