views:

572

answers:

4

Hi

i want to compile a c++ program using .NET2.0 compiler. so i navigate to c:\windows\Microsoft.Netframework\2.0.57\ and uses csc compiler to compile.

It shows lot of errors.

But it compiles csharp file. But in visual studio it compiles. so i think that in visual studio c++ copiler installed i think so.

filename test.cpp

using namespace System;

class test

{

void disp()

{

  Console::WriteLine("Hello");

}

};

void main()

{

test *t=new test();

t->disp();

}

so plz tell me is it possible to compile c++ file using .net framework 2.0 based comiler at command prompt and how?

+2  A: 

csc is the C# compiler, so you shouldn't be surprised that it doesn't compile C++.

Use cl (the C++ compiler) with the /clr switch to compile C++/CLI code. Alternatively, if you've got a solution/project file, use msbuild.

Note that the C++ compiler doesn't ship with .NET, unlike the C# compiler.

Jon Skeet
+1  A: 

It shouldn't be a huge surprise that the C# compiler doesn't like the C++ code; you might as well feed it vb / java / whatever - it isn't going to be legal.

To compile C++, you'll need the C++ compiler, perhaps from C++ Express Edition. Note that for this to compile into mixed/IL it'll been to be managed C++.

Marc Gravell
You two should merge to one super hero :)
VVS
sounds painful... and our families might object (maybe, maybe not)
Marc Gravell
"By your powers combined I am Captain Planet."
Otis
A: 

csc is the compiler for csharp, not C++

The easiest way to compile from the command line is to use msbuild, and pass it the name of your project (or solution file).

Binary Worrier
A: 

Exactly why do three people say the same thing? "csc is the C# compiler".

I don't know about you guys, but I understood it the first time I read it. I suppose it has something to do with intelligence and stuff like that ;)

You might also notice that they posted within minutes of each other, so maybe they just didn't refresh to see someone had answered it before adding their own replies
Otis
He might also have noticed that this was an improper use of an *answer* when it should have been a comment - not much point downvoting though...
ShuggyCoUk