Can I use symbols defined in a .c file in a .cpp file?
I prefer coding in C but I'm using DirectX which is a massive pain to use without C++ so all my files are .c except the ones that deal with DirectX. However whenever I try to link a C file with external symbols that are in a C++ file or vice versa I get unresolved external symbol linker error. Is it possible to link a project that uses .cpp and .c and have the symbols be recognized?
Solution 1:
Can I use symbols defined in a .c file in a .cpp file?
Yes, you can, with the requirement that the names mustn't be reserved in C++ (such as keywords that don't exist in C etc.).
In order to use the C names in C++, they must be declared with C language linkage using a extern "C"
declaration.