• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • 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 OlivaresSoftware ArchitectCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Jaime OlivaresSoftware ArchitectCommented:
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 OlivaresSoftware ArchitectCommented:
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 OlivaresSoftware ArchitectCommented:
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 OlivaresSoftware ArchitectCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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