I'm working on migrating a large project from VS2012 to VS2015 (baby steps, I know), and I'm running into an issue with C headers no longer compiling, erroring out on reserved c++ keywords - even though they're being included with extern C.
Here's a simplified example (Compiles in 2012, but not 2015)
main.cpp
extern "C" {
#include "cheader.h"
}
int main()
{
printfFromC();
return 0;
}
cheader.h
#ifndef HEADER_H
#define HEADER_H
extern int export;
int printfFromC();
#endif
ctest.c
#include "cheader.h"
#include <stdio.h>
int export = 0;
int printfFromC()
{
export++;
return printf("Hello from C (invocation %d) !\n", export);
}
with the following errors:
------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
main.cpp
c:\[...]\cheader.h(4): warning C4091: 'extern ': ignored on left of 'int' when no variable is declared
c:\[...]\cheader.h(4): error C2143: syntax error: missing ';' before 'export'
c:\[...]\cheader.h(4): error C3378: a declaration can be exported only from a module interface unit
Edit:
I made a mistake in creating the example - the keyword that's the cause of the trouble is export
- not any c++ reserved keyword as I first thought. The example below has been modified to use int export
instead of int new