External symbol link error when "compile as" set to 'default'
<p>I am using Visual Studio 2013. I have a global variable declared in a C source file (<code>file1.c</code>) and used in a method defined in a C++ source file (<code>file2.cpp</code>). A header included from both files declares the variable as <code>extern</code>. The project property <code>C\C++ -&gt; Advanced -&gt; compile as</code> is set to <code>defualt</code>, which according to the documentation means the compiler uses the file extension to infer file type. This setup results in an <code>unresolved external symbol</code> linking error. If I set this option to either <code>Compile as C code</code> or <code>Compile as C++ code</code>, the project compiles and link without an error. I fail to understand this behavior. (Btw, under linux/GCC the code compiles OK).</p>

<p>Here's a minimal example reproducing the problem:</p>

<pre><code>// file1.h
extern int g_i;

// file1.c
#include "file1.h"
#include "file2.h"

int g_i;
int main() {
    g_i = 1;
    foo();
    return 0;
}

// file2.h
#ifdef __cplusplus
extern "C"
#endif
void foo();

// file2.cpp
#include "file1.h"
#include "file2.h"

void foo() {
    int i = g_i;
}
</code></pre>