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?
Thanks.
ANSWER
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... :
Thanks, Pavel.
If the C++ compiler provides its own versions of the C headers, the versions of those headers used by the C compiler must be compatible. Oracle Developer Studio C and C++ compilers use compatible headers, and use the same C runtime library. They are fully compatible.
It is not possible to mix C and C# code in the same file. However, you can replicate any C code (except for calling CreateRemoteThread ) in raw C# using unsafe code and/or P/Invoke. That's completely impossible, unless you write your own compiler.
If you are compiling the C code together, as part of your project, with your C++ code, you should just need to include the header files as per usual, and use the C++ compiler mode to compile the code - however, some C code won't compile "cleanly" with a C++ compiler (e.g. use of malloc will need casting).
Yes using C# and C++ for your product is very common and a good idea. Sometimes you can use managed C++, in which case you can use your managed C++ module just like any other .
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With