How to find out if a project is C or C ++ in Visual Studio?

How does Visual Studio know if a project is C or C ++? Is there any configuration or assembly option that indicates this?

Does VS use the use of the C compiler for C and the C ++ compiler for C ++?

+4
source share
3 answers

Does VS use the use of the C compiler for C and the C ++ compiler for C ++?

No

The cl compiler is smart enough to know (based on the file extension) if the file is a .cpp or .cc file, which it treats as a C ++ file. And the cl compiler will consider the .c file as the source C program file and compile it accordingly. Although it downloads a separate dll file to compile C and C++ files. But this implementation is defined.

However, there is a switch to override cl behavior based on file extension.

To compile the C ++ source file (even with the extension .c ), the command would be: cl /TP yourfile.c Note that the file must contain valid C ++ code.

And to compile as the source C file (with the extension .cpp ) the command will be: cl /TC yourfile.cpp note that the file must contain valid C code.

+7
source

In addition to the extension, if you go to File Properties->Advanced , there is the Compile As option, which can be used to explicitly treat code as C code.

It generates /TP for C ++ and /TC for C.

As Joachim noted in the comments, VC ++ is not exactly the most suitable compiler on the planet, so choosing β€œany job” can be a really smart option.

+2
source

There are no C or C ++ projects. Any project can have mixed C, C ++ and other language files.

It is not clear what answer you are expecting for the second question. The C language is compiled with the C compiler and the C ++ language with the C ++ compiler. It is hard to imagine what other cases are possible. Two compilers may or may not be implemented as a single executable program, but this is a rather uninteresting detail.

0
source

All Articles