2

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?

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Where can I get the cl.exe without installing Visual Studio?
@JinKwon: No idea, I'm afraid.
@JinKwon You can install Build Tools for Visual Studio. It contains bunch of command-line tools useful for build servers. You can pick required components (like c++ compiler) and it doesn't come with Visual Studio itself. Note, that it may require Visual Studio license anyway. In the moment you can download it here (bottom of page)
1

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++.

3 Comments

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

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.