Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

How to Use .NET to compile C++ code

Hi I'm new to .Net and C++
I am trying to use .Net to compile my C++ code.  Does anyone know how to do this?  I'm not sure where to begin.

Thanks
0
BBrian
Asked:
BBrian
  • 7
  • 5
  • 3
1 Solution
 
Jaime OlivaresCommented:
If your C++ is standard, non managed C++. Then you can make it as usual. Create a new Project in File -> New -> Project -> Win32 console application (I guess your app is console based. If not, please advice)
0
 
axsaxsCommented:

If you download the .NET Framework (for instance here: http://msdn.microsoft.com/netframework/downloads/framework1_1redist/), after installing you will have the Microsoft C/C++ compiler, which is called "cl" and can compile standard C++ source code.

You can find compiler options here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_compiler_reference.asp

Altough not 100% ANSI-ISO C++ compatible, this new version of the Microsoft C++ compiler is quite standard and offers, IMHO, some of the best optimizations in the "free" compilers market.

0
 
BBrianAuthor Commented:
Here's the probem....when I paste this code..

#include <iostream.h>
void main ( )
{
      cout <<"Hello World"<< endl;
}


I get errors.  It doesn't recognize the iostream.h file.  It says there is no such file directory exists.

0
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 
Jaime OlivaresCommented:
type with:

#include <iostream>

don't use .h extension.
0
 
BBrianAuthor Commented:
ok..i omitted the .h extention..but i still get..

There is no build command line to execute.
Performing Makefile project actions
GenTest2 : error PRJ0003 : Error spawning ''.
0
 
Jaime OlivaresCommented:
How have you created your project? which options?
0
 
BBrianAuthor Commented:
I chose...

1.  Visual C++ projects
2.  Under The General Tab...I selected...
     MakeProjectFile
3.  The wizard comes up..then I click finish
4.  Add a new item to the project
5.  I select a .cpp file


Then I paste this code into the .cpp file

#include <iostream>
void main ( )
{
      cout <<"Hello World"<< endl;
}


and i get the error..
0
 
Jaime OlivaresCommented:
Yes, but which kind of project have selected in the Wizard? there are many. Mus be console application.
0
 
BBrianAuthor Commented:
There are five tabs..

1.  .NET
2.  ALT
3.  MFC
4.  WIN32
5.  GENERAL

I most recently tried selecting general and then clicking on MakeProjectFile
but I also tried clicking on Win32 then clicking on Win32Console Project

I got the same error either way.

am I doing something wrong?
0
 
Jaime OlivaresCommented:
for a win32Console, there is an option that says 'Simple hello world application", choose it, compile and run it. If succefull, replace main function internals with your code.
0
 
BBrianAuthor Commented:
I don't see that option.
0
 
axsaxsCommented:
Ok. First of all correct the code:

#include <iostream>
void main ( )
{
     std::cout <<"Hello World"<< std::endl;

    char c;
    std::cin >> c; // just press any key
}

In fact you are using the std namespace. IMHO, forget the "Simple hello world"... it's better to learn to code from scratch!

Check out the steps:

1. New C++ project
2. New Win32 console project
3. Finish
4. Paste the code
5. Wipe out "precompiled headers" (Project/Properties then C/C++/Precompiled Headers choose: Not using precompiled headers)
6. Run/debug program.
7. Press any key + enter to exit



0
 
BBrianAuthor Commented:
Hey Axsaxs it worked....

I had to remove this code though..


#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
      return 0;
}

and replace it with my hello world code...


if I leave both in i get this error

Linking...
Win32ConsoleProject.obj : error LNK2005: _main already defined in HelloWorld.obj
Debug/Win32ConsoleProject.exe : fatal error LNK1169: one or more multiply defined symbols found
0
 
axsaxsCommented:

That's because the "stdafx.h" is the include for the pre-compiled headers. It's not a bad thing to have pre-compiled headers (it can speed up things if your project grows large), but it is Microsoft-specific. So, I'd rather prefer not to have them. But, there are some techniques to have precompiled headers without the "stdafx.h", but that should be the answer to another question... ;)



0
 
BBrianAuthor Commented:
Thanks alot
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now