Cheeso Cheeso - 1 year ago 114
C Question

Can I mix C++ and C in a single project in Visual Studio?

I have a a Win32 DLL project in VS2008, it is written in a handful of C modules.

Because I also want to be able to build outside VS2008, with no dependency on VS2008, I have produced a custom makefile, that does all the build and link steps. All this is set up just fine.

Now I'd like to add a couple C++ modules to this DLL.
I have modified the custom makefile to compile the .cpp modules as C++, and the .c modules as regular C (/Tc) . This all works. It links everything together, no problem .

Can I configure the VS2008 project to do the same?

Can I mix C++ and C in the same VS2008 project?

Or do I need a custom build step for this?



I had the VS2008 project set to compile as C. I needed to change it to Compile As "Default". Right click the project, select Properties, and then... :

alt text

Thanks, Pavel.

Answer Source

First of all, you shouldn't even need /Tc if you're building it yourself - cl.exe uses file extension to determine the type, so .c files will be compiled as C by default, and .cpp and .cxx files as C++.

For VS projects, it works in exact same way, except that you can't override this behavior (or at least I do not know how).