tags:

views:

86

answers:

2

Possible Duplicate:
Compiling C code for .NET

I have a bunch of C source code and I want to compile it so it uses the .NET framework. I downloaded Microsoft Visual C++ and chose new CLR project. I then added all my C code, and I tried to compile the files. It said

cl : Command line error D8045: cannot compile C file '..\..\..\..\..\Downloads\lzma912\C\XzDec.c' with the /clr option

Why can't I compile this?

+4  A: 

Try to use the /Tp option so VC++ thinks your source file is C++ code instead of C. In that way you don't have to change your file extension.

Brian R. Bondy
+1, but does VC++ allow implicit casting from a void pointer? That'll cause an error.
mathepic
@Mathepic: That's just to get past the first error, no doubt he'll have other errors after.
Brian R. Bondy
At minimum he'll be forced into the C dialect that is the intersection between C++ and C, as modified by the assumptions of building for the CLR. But the first step is to get the compiler to try at all, and the fact that it can only compile C++ for the CLR is a key fact.
RBerteig
+6  A: 

Sometimes, looking to MSDN can clarify the things. You need to force the compiler to treat C files as C++ files. See here.

To quote:

Only C++ source code files can be passed to a compilation that uses /clr. Use /TP to compile a .c file as a .cpp file; see /Tc, /Tp, /TC, /TP (Specify Source File Type) for more information.

Cătălin Pitiș